cellForRowAtIndexPath 在 vi​​ewWillAppear iPhone SDK 3.2 plus 之前调用

发布于 2024-09-11 00:19:25 字数 292 浏览 5 评论 0原文

升级我的 SDK 版本后,我注意到 cellForRowAtIndexPath 总是在 viewWillAppear 之前调用。以前的执行顺序是相反的:viewWillAppear 总是在 cellForRowAtIndexPath 之前调用。由于我的应用程序逻辑经常使用 viewWillAppear 来初始化随后在 cellForRowAtIndexPath 中使用的对象,因此应用程序经常崩溃。

我尝试寻找有关此更改的官方补偿,但没有成功。我可能可以将初始化代码移至 viewDidLoad,但想看看是否有更好的解决方案或有关此行为更改的更多信息。

After upgrading my SDK version I noticed that cellForRowAtIndexPath is always called prior to viewWillAppear. Previously the order of execution was opposite: viewWillAppear would always be called prior to cellForRowAtIndexPath. Because my application logic often used viewWillAppear to initialize objects that are subsequently used in cellForRowAtIndexPath, the application is often crashing.

I tried searching for an official expiation regarding this change with no success. I can likely move my initialization code to viewDidLoad, but wanted to see if there are better solutions or more information about this change in behavior.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

怀里藏娇 2024-09-18 00:19:25

添加一行即可解决您的问题

[self.tableView reloadData];

您只需在 viewWillAppear 末尾

You can just add the line

[self.tableView reloadData];

at the end of viewWillAppear and your problem will be fix

汐鸠 2024-09-18 00:19:25

它不是“在viewWillAppear之前调用cellForRowAtIndexPath”,而是[super viewWillAppear:animated]会调用UITableView的委托。

我犯了同样的错误,我花了很多时间才找到它。

It is not "cellForRowAtIndexPath called before viewWillAppear", it is [super viewWillAppear:animated] will call UITableView's delegate.

I made the same mistake and it took me a lot of time to find it.

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