iPhone / iOS中viewDidAppear,viewDidLoad之间的区别? [英] Difference between viewDidAppear, viewDidLoad in iPhone/iOS?

查看:107
本文介绍了iPhone / iOS中viewDidAppear,viewDidLoad之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

底线是,我一直在开发应用程序,似乎如果我在 viewDidLoad UIAlert $ c>,它被调用两次(来自 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.

推荐答案

UIView对象可以加载到内存中并多次释放,而不会被添加到视图堆栈中并显示在显示。

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.

我的猜测是你有2个引用这个视图(可能是nib文件中的一个?),所以它被加载,然后在第二个引用时被释放加载并分配给同一属性,然后只将后者添加到视图堆栈。您可以通过在viewDidLoad和viewDidAppear方法中打印出(NSLog)self的整数值(%ld,(long int)self)来看到这一点。

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.

这篇关于iPhone / iOS中viewDidAppear,viewDidLoad之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆