Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 925
dgund Avatar asked Jun 21 '12 14:06

dgund


People also ask

How do you refresh a view controller?

In the ViewDidLoad include a loadData() function to prepare the data. This is executed in the initial run. When you want to reload, call loadData() again to get the data from model. In a tableView call reloadData() or in a regular view setNeedsDisplay().

How can you reload a ViewController after dismissing a modally presented view controller in Swift?

Swift 5: You can access the presenting ViewController (presentingViewController) property and use it to reload the table view when the view will disappear. When you dismiss the SecondViewController, the tableview of the FirstViewController will reload. In my case, presentingViewController is SecondViewController.

How do I get navigation controller root view controller?

The root view controller is simply the view controller that sits at the bottom of the navigation stack. You can access the navigation controller's array of view controllers through its viewControllers property. To access the root view controller, we ask for the first item of the array of view controllers.

What is pageview controller in iOS?

The PageViewController is used in many of the iOS applications to let the user navigate between the various pages of the content of the application. The navigation can be controlled programmatically in the application. The PageViewController uses the transition that we specify to animate the change.


2 Answers

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.

like image 59
Sergey Kalinichenko Avatar answered Nov 15 '22 13:11

Sergey Kalinichenko


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

Check about this here:

UIView Programattion Guide

like image 36
Antonio MG Avatar answered Nov 15 '22 14:11

Antonio MG