导航返回时重新加载 UITableView? [英] Reload UITableView when navigating back?

查看:14
本文介绍了导航返回时重新加载 UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 UITableView 的顶级 UIViewController.顶层 UIViewController 实例化一个 NavigationController,并将另一个 UIViewController 推送到 NavigationController 上.IE.我们进入一个新的、第二种观点.第二个视图在左上角有一个常用的返回"按钮,可让您导航回顶层视图.

I have a top level UIViewController that contains a UITableView. The top level UIViewController instantiates a NavigationController, and pushes another UIViewController onto the NavigationController. I.E. we push into a new, second view. This second view has the usual "Back" button in the upper left hand corner to allow you to navigate back to the top level view.

当从第二个视图导航回顶层视图时,是否可以通过调用 使用第二个视图中生成的数据在顶层视图中重绘 UITableViewcellForRowAtIndexPath 在顶层,如果是这样,如何做到这一点?

Is it possible, when navigating back to the top level view from the second view, to redraw the UITableView in the top level view, using data generated in the second view, by calling cellForRowAtIndexPath in the top level and if so, how does one do this?

推荐答案

你需要做的就是这个(在你的 UIViewController 中有一个 UITableView).此时您不必担心单元级别会发生什么.

All you need to do is this (in your UIViewController that has a UITableView). You don't have to worry about what happens at cell-level at this point.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.tableView reloadData]; // to reload selected cell
}

只需将上面的代码添加到您的控制器,当您从第二个视图返回时,您就会发现正确的事情发生了.对 reloadData 的调用告诉表格视图它需要从模型中刷新其单元格,其他一切都很好.

Just add the code above to your controller, and you'll see that the right thing happens when you come back from your second view. The call to reloadData tells the table view that it needs to refresh its cells from your model, and everything else follows nicely.

这篇关于导航返回时重新加载 UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆