我应该在哪里加载 UISwitch 的状态?

发布于 2024-12-04 22:48:28 字数 408 浏览 0 评论 0原文

在我看来,我目前正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

長街聽風 2024-12-11 22:48:28

您可以在上一个视图中加载 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文