开发者

push viewcontroller using UINavigationController sometimes calls viewDidAppear: and viewWillAppear:

开发者 https://www.devze.com 2022-12-31 13:03 出处:网络
When pushing a viewcontroller using UINavigationController into the view: 开发者_JAVA技巧What is necessary for it to trigger

When pushing a viewcontroller using UINavigationController into the view:

  1. 开发者_JAVA技巧What is necessary for it to trigger viewDidAppear: and viewWillAppear: ?
  2. What makes it fail to not trigger viewDidAppear: and viewWillAppear: ?

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


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.

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.


Check that you've got the function name exactly right, for example:

- (void)viewWillAppear:(BOOL)animated

For example, if you forget to declare the animated parameter, your function won't get called.

This may sound obvious, but I've made this mistake and since the original post doesn't have a code sample I thought I'd share!

0

精彩评论

暂无评论...
验证码 换一张
取 消