1

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.

4

2 回答 2

2

您只需添加该行

[self.tableView reloadData];

在 viewWillAppear 结束时,您的问题将得到解决

于 2011-05-22T08:05:30.923 回答
1

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

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

于 2011-12-02T09:18:22.180 回答