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

- 87
- 1
- 7
-
viewDidAppear must be called. Try putting NSLog instead if you are checking with breakpoint – Rahul Wakade Mar 11 '13 at 05:48
-
1`viewDidAppear` always gets called in my apps. Make sure that in your `viewWillAppear:` method that you call `[super viewWillAppear:animated]`. Call the proper `[super xxx]` in your other methods too. – rmaddy Mar 11 '13 at 05:53
4 Answers
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
- the first time the view is needed to be shown
- sometimes when viewController needed to be reloaded again, because it is purged from memory for some low memory reason.
In your case, when you pop back, the viewController is already loaded, so no need to call viewDidLoad
again.

- 34,169
- 30
- 118
- 167
-
-
ok then in ur case ..`viewWillAppear` and `ViewDidAppear ` should be called ryt...but `viewWillAppear` called only not `ViewDidAppear ` – Christien Mar 11 '13 at 05:51
-
When a ViewController's view gets added to UIWindow, `viewDidAppear` gets called. When you push new viewController on top of it, the previous one doesn't get removed from UIWindow. So when you pop back, the controller is still in UIWindow hierarchy, so no need to re add it to UIWindow again. Therefore `viewDidAppear` won't get called – Krishnabhadra Mar 11 '13 at 05:54
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.

- 1
- 1

- 1,608
- 1
- 14
- 27
-
2
-
ya but didnt get the logic y only `viewWillAppear` will get called on navigation back ...not other – Christien Mar 11 '13 at 05:35
-
Because when you back that view controller already created. viewDidLoad called in initializing moment only if that already created it not fire. ViewWillAppear call every time it come to screen. – Hasintha Janka Mar 11 '13 at 05:40
-
Difference between didappear and willappear is willappear called befor the event and didappear called after event(when it done). – Hasintha Janka Mar 11 '13 at 05:42
-
1
-
2Note - this is true for iOS5 and earlier. iOS6 does not unload views anymore. – Abizern Mar 12 '13 at 10:43
First of all, nice question @user2102546. Checkout here the perfect reason for your query.
viewDidLoad only gets called if view controller's views were unloaded, and need to be reloaded.
Normally, if you use a navigation controller, and go back to a previous view with one of the pop methods, viewDidLoad does not get called again, because the view are not unloaded yet
.
However, the system can unload the views of any view controller when it is not frontmost in order to free up memory, so viewDidLoad can get called any time a view controller is about to be presented. You need to write your code to respond correctly to the different events.
Enjoy Programming!!

- 4,637
- 2
- 20
- 34
-
if we consider the above image by Hasintha and ur answer ...`viewDidLoad does not get called again, because the view are not unloaded yet.` fine the ..`viewdidload will not be called as not unloaded but viewWillAppear and ViewDidAppear both should be called ` – Christien Mar 11 '13 at 05:46
-
@Christien, Yes, Both viewWillAppear & ViewDidAppear, will be called on navigation back. – Niru Mukund Shah Mar 11 '13 at 05:53
I don't have a complete answer for you but I hope this helps.
viewDidLoad is a callback for modifying a view after the load event has happened. In your case, the view has already loaded. The fact that it is not in view doesn't mean it has been unloaded from memory.
viewDidAppear: While I don't know why this event isn't firing and would be happy if someone else would fill in the gap.

- 190
- 7