gpt4 book ai didi

iPhone viewWillAppear 不触发

转载 作者:IT王子 更新时间:2023-10-29 07:28:29 25 4
gpt4 key购买 nike

我读过许多关于人们在 正确创建 View 层次结构时遇到 viewWillAppear 问题的帖子。我的问题是我不明白那是什么意思。

如果我创建一个 RootViewController 并在该 Controller 上调用 addSubView,我希望添加的 View 能够连接到 viewWillAppear 事件。

有没有人有一个复杂的编程 View 层次结构的示例,它可以在每个级别成功接收 viewWillAppear 事件?

Apple 的文档状态:

Warning: If the view belonging to a view controller is added to a view hierarchy directly, the view controller will not receive this message. If you insert or add a view to the view hierarchy, and it has a view controller, you should send the associated view controller this message directly. Failing to send the view controller this message will prevent any associated animation from being displayed.

问题是他们没有描述如何做到这一点。 “直接”是什么意思?如何“间接”添加 View ?

我对 Cocoa 和 iPhone 还很陌生,所以如果除了基本的 Hello World 废话之外还有来自 Apple 的有用示例,那就太好了。

最佳答案

如果您使用导航 Controller 并设置其委托(delegate),则不会调用 View {Will,Did}{Appear,Disappear} 方法。

您需要改用导航 Controller 委托(delegate)方法:

navigationController:willShowViewController:animated:
navigationController:didShowViewController:animated:

关于iPhone viewWillAppear 不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/131062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com