我知道在pop / push视图中没有调用viewWillAppear,但我确实需要这种方法。这是我尝试的
我添加了UINavigationControllerDelegate并采用
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[viewController viewWillAppear:animated];
}
-(void)viewWillAppear
{
NSLog(@"Log");
}
但仍未调用viewWillAppear
修改
AppDelegate.m
self.navigationController = [[UINavigationController alloc]init];
[self.window setRootViewController:self.navigationController];
FirstView *fview = [FirstView]alloc]init];
[self.viewController pushViewController:fview animated:YES];
FirstView.m
....
-(void)viewWillAppear
{
NSLog(@"Logged");
}
...
答案 0 :(得分:6)
线索在这里:
[viewController viewWillAppear:animated];
}
-(void)viewWillAppear
您调用一个带一个参数的方法。但是你的方法没有。在Objective C术语中,这是一种完全不同的方法。
它应该是这样的:
-(void)viewWillAppear:(BOOL)animated {
// blah
}
答案 1 :(得分:0)
我的工作代码:
self.navController = [[[CustomNavigationController alloc] initWithRootViewController:[[[HomeViewController alloc] init] autorelease]] autorelease];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];