Difference between viewDidAppear, viewDidLoad in iPhone/iOS? [duplicate]

强颜欢笑 提交于 2019-12-13 12:07:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!