有时 Tableview reloadData 没有被执行
我有一个从两个不同地方调用的视图控制器。
1)我从根控制器调用它。它被显示并填充。添加按钮完美运行。我打开一个模态表单,获取信息并通过其委托将其返回到视图控制器。
- (void)itemsAddViewController:(AddItemView *)itemsAddViewController didAddItem
(OrdersDetails *)orderDetail;
{
if (orderDetail) {
[orderDetailItems addObject:orderDetail];
}
[self fetchOrderDetails];
[lineItemsTableView reloadData];
[self dismissModalViewControllerAnimated:YES];
}
但是,当我从另一个视图(在拆分视图的右侧)调用它时,相同的代码不会重新加载表。它添加了数据——如果我离开表单并返回,数据就在那里,但表视图没有被刷新。当我单步执行代码时,它会获取该行,但然后会像没有看到它一样遍历它。
I have a view controller that is called from 2 different places.
1) I call it from a root controller. It is shown and populated. The add button works perfectly. I open a modal form, get the information and return it to the view controller via it's delegate.
- (void)itemsAddViewController:(AddItemView *)itemsAddViewController didAddItem
(OrdersDetails *)orderDetail;
{
if (orderDetail) {
[orderDetailItems addObject:orderDetail];
}
[self fetchOrderDetails];
[lineItemsTableView reloadData];
[self dismissModalViewControllerAnimated:YES];
}
However, when I call it from another view (on the right side of the split view), this same code does NOT reload the table. It adds the data -- if I leave the form and come back, the data is there, but the tableview is not being refreshed. When I step through the code, it gets the the line, but then goes over it like it doesn't see it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当模态视图控制器出现在包含 -itemsAddViewController:didAddItem: 的视图控制器上时,底层控制器的视图不可见,因此如果控制器收到内存警告,则会被卸载。
因此,当您调用
-itemsAddViewController:didAddItem:
时,您的视图可能无法加载,并且您的lineItemsTableView
出口可能为nil
。您对reloadData
的调用需要移至-viewWillAppear:
以避免假设控制器的视图在不可见时可以具有持久状态。When a modal view controller is presented over the view controller containing
-itemsAddViewController:didAddItem:
the underlying controller's view is not visible and will therefore be unloaded if the controller receives a memory warning.As a result your view may not be loaded and your
lineItemsTableView
outlet may benil
when you call-itemsAddViewController:didAddItem:
. Your call toreloadData
would need to move to-viewWillAppear:
to avoid assuming that your controller's view can have a persistent state when it is not visible.