您的位置:首页 > 移动开发

UINavigationController and viewWillAppear / viewDidAppear

2011-06-06 21:47 453 查看
源自:http://www.idev101.com/code/User_Interface/UINavigationController/viewWillAppear.html

When you push or pop a view controller on/off a navigaction controller's stack, the usual viewWillAppear / viewDidAppear methods aren't called. If you want to ensure they're always called, just add the UINavigationControllerDelegate protocol to your root view controller:

@interface RootViewController : UIViewController <UINavigationControllerDelegate> {
UINavigationController *navController;
}


Then implement these two methods:

- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[viewController viewWillAppear:animated];
}

- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[viewController viewDidAppear:animated];
}


Be sure to set the root view controller as the delegate for the nav controller. Now viewWillAppear / viewDidAppear will be called whenever a controller is pushed/popped from the stack.

If you want to call the viewWillDisappear/viewDidDisappear methods, your view controller still has to do that manually before popping itself off the nav stack.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐