使用UINavigationController推送viewcontroller有时会调用viewDidAppear:和viewWillAppear: [英] push viewcontroller using UINavigationController sometimes calls viewDidAppear: and viewWillAppear:

查看:81
本文介绍了使用UINavigationController推送viewcontroller有时会调用viewDidAppear:和viewWillAppear:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用UINavigationController将视图控制器推入视图时:

When pushing a viewcontroller using UINavigationController into the view:


  1. 触发
    viewDidAppear:和viewWillAppear所需的内容:?

  2. 是什么让它无法触发viewDidAppear:和viewWillAppear:?

我们我们很难依靠这些方法被触发与否。

We are having a hard time relying on wether those methods gets triggered or not.

推荐答案

UINavigationController直接在调用pushViewController时被推送的控制器上调用这些方法:animated:同样,UITabBarController直接调用这些方法当你切换标签时,UIViewController在你使用presentModalViewController时调用它们:animated:。当视图控制器的视图添加到窗口时,它们也会被调用。我从未见过这些方法在这些特定的上下文中无法被调用。

UINavigationController calls these methods directly on the controller that's being pushed when you call pushViewController:animated: Similarly, UITabBarController calls these methods directly when you switch tabs, and UIViewController calls them when you use presentModalViewController:animated:. They also get called when a view controller's view is added to a window. I've never seen these methods fail to get called in these specific contexts.

现在请记住,这些方法仅在被推送或呈现在这些方法中的控制器上被调用具体情况。例如,如果将视图控制器的视图添加为除UIWindow之外的某个视图的子视图,则不会调用这些方法。 Apple的文档声明视图控制器仅用于全屏视图,通常使用上述方法之一来呈现。可以忽略Apple的建议并将视图控制器与另一个视图控制器的子视图相关联,但是您必须手动将viewWill / DidAppear / Disappear调用从容器视图控制器委派给嵌套控制器。

Now bear in mind that these methods only get called on the controller being pushed or presented in these specific contexts. These methods won't get called, for example, if you add your view controller's view as a subview of some view other than the UIWindow. Apple's documentation states that view controllers are intended only to be used with full screen views, which are typically presented using one of the methods described above. It's possible to ignore Apple's advice and associate a view controller with a subview of another view controller, but you'll have to delegate the viewWill/DidAppear/Disappear calls from the container view controller to the nested controller manually.

这篇关于使用UINavigationController推送viewcontroller有时会调用viewDidAppear:和viewWillAppear:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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