如何使用tabbar和navigationController时调用viewWillAppear
采用如下方式:
App—>RootViewController—>UINavigationController—>UIViewController
发现UIViewController接收不到viewWillAppear相关的四个函数。
经过多次试验,发现如下方法,可以解决:
在RootViewController的Init中加入如下代码(红色字体)
tabBarController.viewControllers = [NSArray arrayWithObjects:tabNav1,tabNav2, nil];
self.tabBarController.selectedViewController = tabNav1;
同时添加:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tabBarController.selectedViewController viewWillAppear:animated];
}- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[viewController viewWillAppear:NO];
}
为什么没有调用,可参考: