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?
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().
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.
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.
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.
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.
You should use viewDidAppear
, viewDidLoad
is only called after the view is loaded the first time.
Check about this here:
UIView Programattion Guide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With