问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/3594046/difference-between-viewdidappear-viewdidload-in-iphone-ios