views:

630

answers:

1

My RootViewController contains a table view and a navigation bar. Upon tapping a row, another view controller is pushed to the stack, namely SecondViewController. If I click the Back button, SecondViewController is popped out of the stack, but the parent view controller's data is out of date.

How could I reload RootViewController's data? My first attempt is to implement

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

and call viewdidLoad again.

The problem is, on first load, viewDidLoad would be called twice.

+3  A: 

Load the data in the table in the viewWillAppear: method instead of viewDidLoad. viewWillAppear will be called every time your view is going to appear whereas viewDidLoad is called just once when the view is created.

So loading the data in viewWillAppear: will make sure your table has the latest data whenever it is displayed.

lostInTransit
Exactly what I was looking for. Thanks a bunch!
QAD