I am trying to call the UIBarButtonItem
when the back button of that controller is pressed.This is my code.I have put the initialization in viewDidLoad
and viewWillAppear
but the method is not being called.
UIBarButtonItem *exampleButton = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:self action:(@selector(backToViewController:))];
self.navigationItem.backBarButtonItem = exampleButton;
-(void)backToViewController:(UIBarButtonItem*)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
}