5

I am working with a UINavigationController in my app. In viewDidLoad, the root view controller acquires information from the internet, parses it, and displays it.

When going to another view in the UINavigationController, and then going back to the root UIViewController, the information in the controller is not reloaded. This leads me to think that viewDidLoad is not being called.

What method should I use to ensure this information is reloaded when the root view controller is popped back to in the UINavigationController?

Edit:

Thanks for the quick responses guys, it means a lot. One more question regarding your answers: viewWillAppear or viewDidAppear? Are there pros/cons for each?

dgund
  • 3,459
  • 4
  • 39
  • 64
  • viewWillAppear will be processed right before the view is displayed, viewDidAppear will be processed after view is pushed on top of the stack. – Kyle Jun 21 '12 at 14:36

4 Answers4

9

You should process viewWillAppear: or viewDidAppear:, depending on whether you'd like a reload to happen before or after thew view shows up on the screen. viewDidLoad is called only once, when the view is loaded.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • Depending on when your information is retrieved and processed from the internet, you may also need to call `setNeedsDisplay` which will tell the device the view needs to be refreshed. – Kyle Jun 21 '12 at 14:35
  • 2
    @DevinGund Here is a [link](http://stackoverflow.com/a/5659007/335858) to an excellent answer to your follow-up question. – Sergey Kalinichenko Jun 21 '12 at 14:39
1

You should use viewDidAppear, viewDidLoad is only called after the view is loaded the first time.

Check about this here:

UIView Programattion Guide

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
Antonio MG
  • 20,382
  • 3
  • 43
  • 62
1

And you are right, it's not being called. If you want to call it everytime you go to that UIViewController (you have one inside your UINavigationController) just put it on the viewDidAppear or viewWillAppear.


viewWillAppear happens before viewDidAppear. For speed purposes, I would do it on the viewDidAppear on a secondary thread in a async way, so the UI thread wouldn't slow down. Once the data was retrieved, I would update the view.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
1

viewDidLoad is only called when the View Controller is initially created, or if it was unloaded because it was hidden and the application received a memory warning. You can alternately implement viewWillAppear: or viewDidAppear: to refresh your UI.

logancautrell
  • 8,762
  • 3
  • 39
  • 50