iPhone/iOS 中 viewDidAppear 和 viewDidLoad 之间的区别?
底线是,我一直在开发一个应用程序,似乎如果我在 viewDidLoad
中放置一个 UIAlert
,它会被调用两次(从 的委托方法)代码>UIImagePickerController
)。如果我把它放在 viewDidAppear 中,它就会被调用一次。
我查看了文档,但它让我感到困惑。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIView 对象可以多次加载到内存中并释放,而无需添加到视图堆栈并出现在显示器上。
我的猜测是,您对该视图有两个引用(也许一个 nib 文件中的一个?),因此它正在被加载,然后在加载第二个引用并将其分配给同一属性时释放,然后只有后者被添加到视图中堆。您可以通过在 viewDidLoad 和 viewDidAppear 方法中打印 (NSLog) self ("%ld",(long int)self) 的整数值来看到这一点。
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.