cellForRowAtIndexPath 在 viewWillAppear iPhone SDK 3.2 plus 之前调用
升级我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加一行即可解决您的问题
您只需在 viewWillAppear 末尾
You can just add the line
at the end of viewWillAppear and your problem will be fix
它不是“在
viewWillAppear
之前调用cellForRowAtIndexPath
”,而是[super viewWillAppear:animated]
会调用UITableView的委托。我犯了同样的错误,我花了很多时间才找到它。
It is not "
cellForRowAtIndexPath
called beforeviewWillAppear
", 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.