Why is viewWillDisapper not called?

Why is viewWillDisapper not being called when I click the button on the myViewController navigation bar?

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 didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MyViewController *myViewController = [[MyViewController alloc] init]; [self.navigationController pushViewController:myViewController animated:YES]; [myViewController release]; } 

// This is MyViewController.m. MyViewConroller is a subclass of UIViewController.

 - (void)viewWillDisappear:(BOOL)animated { // I want to override back button behavior. But, this is not called. } 

viewWillAppear, viewDidAppear, viewDidDisappear, viewDidUnLoad are also not called.

0
source share
2 answers

If you just want to override the behavior of the button on the left navigation bar, you can simply replace leftBarButtonItem with the button using a special 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 UIBarButtonItem view if you wish.

0
source

You must call viewWillAppear in your parent view controller.

http://bit.ly/q9vQiu

-1
source

Source: https://habr.com/ru/post/897044/


All Articles