Why is viewWillDisapper not called?
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];
// This is TheController.m
- (void)tableView:(UITableView *)tableView didSelectRowAt开发者_运维知识库IndexPath:(NSIndexPath *)indexPath {
MyViewController *myViewController = [[MyViewController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];
}
// 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 are not called either.
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];
You can also provide a custom view for the UIBarButtonItem if you prefer.
You should call viewWillAppear in your parent view controller.
http://bit.ly/q9vQiu
精彩评论