I have doubt need to be clear.. I have stack and a navigation controller.now when the stack loads the viewDidLoad
viewWillAppear
viewDidAppear
will be called. when i click some button then this button push me to the new stack , now new stack gives me the option of the back..now when i click on the back of the navigation controller..why only viewWillAppear
will be called ..why not viewDidLoad
and not viewDidAppear
Stack is Last In First Out (LIFO), so when you push new view controllers to the stack, previous viewcontroller will not get destroyed( and they remain in memory). When you pop back, there is no need to recreate the Viewcontroller since it is already in memory. So only viewWillAppear
gets called.
As to why viewDidAppear
doesn't get called in this case, I cant remember where I have read this, but viewDidAppear
gets called after your UIViewController's view was added to the application's UIWindow heirarchy. And this process is done before the UIViewController is shown for the first time.
viewDidLoad
only called when viewControllers views are loaded into the memory. It will be done when
In your case, when you pop back, the viewController is already loaded, so no need to call viewDidLoad
again.
Full life cycle of ios ui explain here.
http://www.verydemo.com/demo_c134_i4568.html
Note By Abizern from comment: this is true for iOS5 and earlier. iOS6 does not unload views anymore.
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