让viewDidAppear/viewWillAppear 在页面加载前始终调用
2012-04-05 17:53
393 查看
viewDidAppear/viewWillAppear in
UINavigationController not be called
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:
Then implement these two methods:
Be sure to set the root view controller as the delegate for the nav controller. Now viewWillAppear / viewDidAappear 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.
UINavigationController not be called
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 / viewDidAappear 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.
相关文章推荐
- iPhone开发 让viewDidAppear/viewWillAppear 在页面加载前始终调用
- 让viewDidAppear/viewWillAppear 在页面加载前始终调用
- 让viewDidAppear/viewWillAppear 在push/pop页面加载前始终调用
- 关于IOS开发中的viewController的viewWillAppear 和viewDidAppear 等调用的总结
- ios view的几种加载函数的区别didFinishLaunchingWithOptions、initWithNibName:bundle、loadView、viewWillAppear
- viewWillAppear和viewDidAppear什么时候被调用
- 解决:IOS viewDidAppear/viewWillAppear无法被调用
- 画面跳转各方法调用的时机-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear、viewDidDisappear
- navigationController中viewWillAppear,viewDidAppear,viewWillDisappear和viewDidDisappeart调用问题
- 关于IOS开发中addSubView上去的viewController的viewWillAppear 和viewDidAppear 等调用的总结
- 直接把View Controller的view addSubview到另一个View,则不会调用viewDidAppear viewWillAppear
- 画面跳转各方法调用的时机-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear、viewDidDisappear
- viewDidAppear中一定要调用[super viewDidAppear]
- iOS 视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途
- iOS模态跳转的页面WebView中加载html调用本机相册会dismiss返回上一个页面解决办法
- (转)viewDidLoad, viewWillDisappear, viewWillAppear等区别及各自的加载顺序
- ios的视图控制器的viewWillAppear和viewDidAppear什么时候被调用
- OS视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear、view
- iPhone开发之解决viewWillAppear不被调用
- ios 自定义tabbar时 viewDidAppear不调用