jaamun
jaamun

Reputation: 181

Back button in UINavigationController

So, I am well aware that when the back button is pressed in classes embedded in UINavigationControllers, the previous view's viewDidAppear() method is called. However, I need the viewDidLoad() method to be called, much like it is with a push segue into a scene. Is there a possible way to do this? Maybe by modifying the method that is called when the back button is pressed? What is the method that is called when the back button is pressed? Thanks.

Upvotes: 0

Views: 250

Answers (2)

occulus
occulus

Reputation: 17012

viewDidLoad is only called when the view has loaded. There's a difference between views being loaded/unloaded and them appearing/disappearing: a view can disappear without being unloaded. Usually iOS will not unload a view, even if it is hidden/replaced by by another view, unless a low memory situation occurs.

Don't ever call viewDidLoad etc. yourself (except for the super call in subclass overrides).

Upvotes: 1

Ankit Thakur
Ankit Thakur

Reputation: 4749

Firstly viewWillAppear and then viewDidAppear is getting called on push back. And for lazy loading of views, it is preferable to add/operate UI subviews in viewWillAppear, and make them set view to nil in viewDidDisappear for memory management.

Upvotes: 1

Related Questions