我应该在哪里加载 UISwitch 的状态?
在我看来,我目前正在尝试从 NSUserDefaults 加载 UISwitch 的状态。这些 UISwitch 位于在 cellforrowatindexpath 中加载的自定义表格视图单元格中。如果我将代码放在 cellforrow 方法中加载开关状态,会不会导致视图在启动时有点滞后,因为该方法被调用了几次,而且我只需要执行一次此代码?
目前,我在 cellforrowatindexpath 委托方法完成其工作后加载它,这对我来说是在 viewdidload 方法中。但问题是,它看起来不太好,因为开关卡入到位,而用户可以看到我不想要的开关。如果我将代码放入 viewwillappear 方法中,则会导致开关全部关闭,因为它们尚未创建。
那么我应该在什么地方从 NSUserDefaults 加载开关状态,以便它看起来不错并且仍然高效?
谢谢!
I am currently trying to load the UISwitch's state from NSUserDefaults in my view. These UISwitch'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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在上一个视图中加载 NSUserDefaults 的数据(如果存在),而不仅仅是通过 NSArray (fe) 给出此参数,并在配置单元后设置它们。
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.