Bottom line is, I've been working on an app, and it seems that if I place a UIAlert
in viewDidLoad
, it gets called twice (from a delegate method of UIImagePickerController
). If I put it in viewDidAppear
, it gets called once.
I've looked through documentation but it just confuses me.
The difference between viewDidAppear and viewDidLoad is that viewDidAppear is called every time you land on the screen while viewDidLoad is only called once which is when the app loads.
viewDidLoad ONLY gets called when the view is constructed - so for example after a view controller initFromNibNamed call when the view is accessed. viewWillAppear is called anytime your view controller was not in view but comes into view - so when your view controller is pushed, viewWillAppear is called.
Notifies the view controller that its view was added to a view hierarchy. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.0+ tvOS 9.0+
viewDidLoad is called after your view is loaded. It is called only once when view is initialized and pushed or presented. viewDidAppear is called once you see the loaded view on screen. It is called after view appeared.
A UIView object can get loaded into memory and released multiple times without ever getting added to the view stack and appearing on the display.
My guess is that you have 2 references to this view (maybe one in a nib file?), so it's getting loaded, then released when the second reference is loaded and assigned to the same property, then only the latter gets added to the view stack. You can see this by printing out (NSLog) the integer value of self ("%ld",(long int)self) in the viewDidLoad and viewDidAppear methods.
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