为什么不调用viewWillDisapper? [英] Why is viewWillDisapper not called?
问题描述
为什么当我在myViewController的导航栏中按下后退按钮时,为什么没有调用viewWillDisapper?
Why is viewWillDisapper not called when I push back button in navigation bar of myViewController?
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
// This is 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的子类.
// This is MyViewController.m. MyViewConroller is subclass of UIViewController.
- (void)viewWillDisappear:(BOOL)animated {
// I want to override back button behavior. But, this is not called.
}
viewWillAppear,viewDidAppear,viewDidDisappear,viewDidUnLoad也不会被调用.
viewWillAppear, viewDidAppear, viewDidDisappear, viewDidUnLoad are not called either.
推荐答案
如果只想覆盖左侧导航栏按钮的行为,则可以简单地将leftBarButtonItem替换为具有自定义操作的按钮:
If you just want to override the left navigation bar button behavior, you can simply replace the leftBarButtonItem with a button with a custom action:
// 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提供自定义视图.
You can also provide a custom view for the UIBarButtonItem if you prefer.
这篇关于为什么不调用viewWillDisapper?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!