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

问题描述

我有一个顶级 UIViewController ,其中包含 UITableView 。顶级 UIViewController 实例化 NavigationController ,并推送另一个 UIViewController NavigationController 。 I.E.我们推进了新的第二种观点。第二个视图在左上角有通常的后退按钮,允许您导航回顶层视图。

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.

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

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:43