当我在myViewController的导航栏中按下按钮时,为什么没有调用viewWillDisapper?
TheController *theController = [[TheController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:theController];
self.naviController = aNavigationController;
[aNavigationController release];
[theController release];
[self.view addSubview:naviController.view];
//这是TheController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MyViewController *myViewController = [[MyViewController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];
}
//这是MyViewController.m。 MyViewConroller是UIViewController的子类。
- (void)viewWillDisappear:(BOOL)animated {
// I want to override back button behavior. But, this is not called.
}
不会调用viewWillAppear,viewDidAppear,viewDidDisappear,viewDidUnLoad。
答案 0 :(得分:0)
如果您只想覆盖左侧导航栏按钮的行为,您只需将leftBarButtonItem替换为带有自定义操作的按钮:
// Place this in you viewDidLoad method
UIBarButtonItem *customBack = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonSystemItemCancel target:self action:@selector(customAction)];
self.navigationItem.leftBarButtonItem = customBack;
[customBack release];
如果您愿意,还可以为UIBarButtonItem提供自定义视图。
答案 1 :(得分:-1)
您应该在父视图控制器中调用viewWillAppear。