iPhone/iOS 中 viewDidAppear 和 viewDidLoad 之间的区别?

发布于 2024-09-16 13:30:36 字数 203 浏览 1 评论 0原文

底线是,我一直在开发一个应用程序,似乎如果我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然 2024-09-23 13:30:36

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文