Reload UITableView when navigating back?

前端 未结 7 1678
醉梦人生
醉梦人生 2021-01-30 06:38

I have a top level UIViewController that contains a UITableView. The top level UIViewController instantiates a NavigationController

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 07:00

    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
    }
    

    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.

提交回复
热议问题