编码自定义 SplitViewController - 我什么时候应该调用 viewWillAppear、viewDidAppear 等......?
我正在从头开始编写自己的 SplitViewController (即通过子类化 UIViewController
而不是 UISplitViewController
)。
它有两个子视图控制器(一个用于左侧面板,一个用于详细右侧面板),我需要向其发送适当的消息(viewWillAppear、viewDidAppear、viewWillDisapppear 和 viewDidDisappear
)。
当我的自定义 SplitViewController 收到这些消息时,我已经转发这些消息并且工作正常。然而,当两个子视图控制器中的任何一个被新的子视图控制器替换时,我正在努力弄清楚何时发送它们,新的子视图控制器也需要接收这些消息。我正在正确添加新 UIViewController
的视图,但未充分调用消息。
我最初的方法是在子 viewController 的 setter 中调用它们,调用 viewWillDisappear
到即将发布的 UIViewController
,并调用 viewWillAppear
到新的UIViewController
设置,但这个是在 viewDidLoad
之前执行的,因此我认为是错误的。
我还看到 UIView 有一个方法 didAddSubview:
,它可能有助于了解何时在相应的 UIViewController
上调用 viewDidAppear
。
任何帮助将不胜感激!
I'm writing my own SplitViewController from scratch (i.e. by subclassing UIViewController
and not UISplitViewController
).
It has two sub-viewControllers (one for the left panel and one for the detail right panel), to which I need to send the appropriate messages (viewWillAppear, viewDidAppear, viewWillDisapppear and viewDidDisappear
).
I am already forwarding those messages when my custom SplitViewController receives them and it works fine. However I am struggling to figure out when to send them when any of the two sub-viewcontrollers is replaced by a new one, which also needs to receive those messages. I am adding the view of the new UIViewController
properly but the messages are not called adequately.
My initial approach was to call them in the setter of the sub-viewControllers, calling viewWillDisappear
to UIViewController
about to be released and viewWillAppear
to the new UIViewController
set, but this one is executed before viewDidLoad
and therefore I presume is wrong.
I have also seen that UIView has a method didAddSubview:
that might be useful to know when to call viewDidAppear
on the correspondent UIViewController
.
Any help would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想镜像 UISplitViewController,似乎最好只使用虚拟的 UIViewController,在调用每个方法时打印出来。
至于您当前的 viewWillDisappear、viewWillAppear 和 viewDidLoad 的排序问题,只需执行以下操作:
If you want to mirror UISplitViewController, it seems best to just have dummy UIViewControllers that print out whenever each method is called.
As for your current problem of the ordering of viewWillDisappear, viewWillAppear and viewDidLoad, just do: