I'm wondering if, once a view controller somewhere in a navigation controller hierarchy is created, is it reloaded when you pop back to it after it has already previously been loaded?
Asked
Active
Viewed 3,085 times
3
-
No. Only viewWillAppear and viewDidAppear are called. You should try it first. – Valent Richie May 26 '13 at 02:27
2 Answers
5
If you're popping/dismissing back to it, viewDidLoad
is not generally called, but viewDidAppear
will.
The exception to this is in iOS versions prior to 6.0, if you received a memory warning, your view could be unloaded, and it will be reloaded when you pop back.

Rob
- 415,655
- 72
- 787
- 1,044
-
you mean if I have a navigation stack of 1(rootViewController),2 and am currently at 1 ie 1 is my *topviewController*. and I go from 1 to 2 and then go back to 1. Isn't 2 kicked out of memory? and if I go back from 1 to 2 again isn't viewDidLoad loaded from **scratch**? – mfaani Sep 18 '16 at 19:48
-
1You're correct, but that's not what the OP asked. He asked whether, when you pop back from 2 to 1, whether `viewDidLoad` is called again on 1. But of course, 2 is typically released when you pop from it and it will be recreated from scratch if you push to a new instance of 2. – Rob Sep 18 '16 at 19:54
-
I never thought of it that way, but I'm not 100% if that is what he was asking. But I guess with the comments now it leaves no doubt. I'd suggest you include this in the answer or differentiate. I was lost for a few minutes... – mfaani Sep 18 '16 at 19:57
-
1Perhaps, but I'm pretty sure about the OP's intent here. It was a completely logical question back in 2013, because in olden days (pre iOS 6), in low memory situations it actually _could_ unload 1 when you pushed from 1 to 2 and when you popped back, it actually might need to reload 1 again. There was much confusion over this topic back then. (This is part of the reason why Apple simplified it, as it created tremendous confusion for negligible gain.) – Rob Sep 18 '16 at 20:03
1
You may refer to this one
Difference between viewDidLoad and viewDidAppear
viewDidLoad is called exactly once, when the view controller is first loaded into memory. This is where you want to instantiate any instance variables and build any views that live for the entire lifecycle of this view controller. However, the view is usually not yet visible at this point.