Search code examples
iosobjective-cmethodsviewdidload

Run method every time view is shown - iOS


I understand that you can use ViewDidLoad to run some code when a view is loaded. However that only happens once. How can I run a method every single time that view is shown. So for example: let says you are currently in ViewController A and you press a UIButton to go to ViewController B. Then you press a button to go back to ViewController A, how would you then re-run the ViewDidLoad code??

I hope my question makes sense. In essence I want to re-run a small method every single time the user is on a particular ViewController.

Thanks for your time, Dan.


Solution

  • viewWillAppear:

    Notifies the view controller that its view is about to be added to a view hierarchy.

    or

    viewDidAppear:

    Notifies the view controller that its view was added to a view hierarchy.