view raw
James Testa James Testa - 9 months ago 89
Objective-C Question

Reload UITableView when navigating back?

I have a top level

that contains a
. The top level
instantiates a
, and pushes another
onto the
. 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.

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


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.