dgund
dgund

Reputation: 3467

Reload root view controller

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?

Upvotes: 5

Views: 4691

Answers (4)

Rui Peres
Rui Peres

Reputation: 25907

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.

Upvotes: 1

logancautrell
logancautrell

Reputation: 8772

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.

Upvotes: 1

Antonio MG
Antonio MG

Reputation: 20410

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

Check about this here:

UIView Programattion Guide

Upvotes: 1

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726539

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.

Upvotes: 9

Related Questions