让viewDidAppear/viewWillAppear 在页面加载前始终调用
2010-08-24 20:42
218 查看
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.
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 在页面加载前始终调用
- PHP教程之PHP调用session_start后页面始终加载的问题研究
- 让viewDidAppear/viewWillAppear 在push/pop页面加载前始终调用
- 让viewDidAppear/viewWillAppear 在页面加载前始终调用
- PHP调用session_start后页面始终加载的问题研究
- 转:PHP教程之PHP调用session_start后页面始终加载的问题研究
- angular 页面加载时可以调用 函数处理
- link and script 调用页面外的内容加载于浏览器上
- 异步加载页面,页面中的js的调用问题
- EXTJS_Tabpanel布局,选项卡加载页面,调用别的jsp页面,截图所示
- C# aspx页面动态加载ascx用户控件 及 利用反射调用其内方法
- Android中Webviw加载H5页面调用本地相机拍照并显示在H5页面上
- 调用 WebView 的 loadUrl 加载页面后 Javascript 脚本不执行
- 在加载aspx页面时,为引用的ascx当中的按钮添加事件,以方便调用aspx页面中的函数
- C# aspx页面动态加载ascx用户控件 及 利用反射调用其内方法
- 在阿里云上部署Django应用后,页面403错误,始终无法加载静态文件的解决方案
- JSP在页面加载时调用servlet的方法
- 在页面没有完全加载完毕前调用Ajax方法会出错
- 使用JQuery 加载页面时调用JS的实现方法