I have a UIBarButtonItem and would like to programmatically set the action that goes to the previous controller (in my case, my previous view is a UITableViewController).
<
You could write this in your viewDidLoad
method:
UIBarButtonItem *btn=[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(btnClick)];
self.navigationItem.leftBarButtonItem=btn;
and then use this:
// call of method
-(void)btnClick
{
[self.navigationController popViewControllerAnimated:YES];
}