开发者

Where should I load a UISwitch's state?

开发者 https://www.devze.com 2023-04-05 06:39 出处:网络
I am currently trying to load the UISwitch\'s state from NSUserDefaults in my view. These U开发者_如何学PythonISwitch\'s are in custom tableview cells that are loaded in the cellforrowatindexpath. If

I am currently trying to load the UISwitch's state from NSUserDefaults in my view. These U开发者_如何学PythonISwitch's are in custom tableview cells that are loaded in the cellforrowatindexpath. If I put my code to load the switches states in the cellforrow method wouldn't that cause the view to lag a bit on startup since that method is getting called a few times and since I only need this code to be executed once?

Currently, I am loading it after the cellforrowatindexpath delegate method has been done doing its stuff which for me is in the viewdidload method. But the thing is, it doesn't look so nice because the switches are snapping into place while the user can see the switches which I do not want. If I put the code into the viewwillappear method, it causes the switches all to be off since they are not created yet.

So in what place should I load the switches state from NSUserDefaults so that it looks nice and is still efficient?

Thanks!


You can load the data for NSUserDefaults in the previous view (if it is there), and than just give this parameters through NSArray (f.e.), and set them after configuring the cell.

0

精彩评论

暂无评论...
验证码 换一张
取 消