Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does viewDidload method call again on going back to a screen in navigation controller?

I am using navigation controller. I have pushed two viewcontroller to navigation stack. When I am coming back to viewcontroller1 from viewcontroller2 using back button of navigation bar then viewdidload method of viewcontroller1 is called again.But as much as I know viewdidload is called only once at loading time. So why is this happening? Please tell me.

Thanks!!

like image 340
Kirti Avatar asked Nov 18 '15 11:11

Kirti


2 Answers

-(void)viewDidLoad called only when view controller is loaded

but if you want to call any method then you can write code in

-(void)viewWillAppear

this method called every time when your view is appear.

like image 118
Ashish Thakkar Avatar answered Oct 28 '22 09:10

Ashish Thakkar


About viewDidLoad

viewDidLoad: is called every time your view controller's view is loaded, not just the first time. The controller's view can be loaded and unloaded multiple times during the lifespan of the controller and viewDidLoad will be called every time. It may be unloaded whenever it's not on screen, usually if memory is low.

Best practices

Remember not to do view controller initialisation in viewDidLoad. This is a common mistake. For stuff that should only happen once when the view controller is loaded, do it in one of the controller's init methods.

like image 37
Rafa de King Avatar answered Oct 28 '22 10:10

Rafa de King