I have a UITableViewController A that is pushing UITableViewController B onto the stack.
In A i have the code:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Trending"
style:UIBarButtonItemStylePlain
target:self
action:@selector(backButtonClicked:)];
backButtonClicked: is also implemented.
B has the title Trending, but when I click it, it doesn't ever reach backButtonClicked:
Why is this?
Try either setting the delegate:
Or using the left button. Sometimes the back button doesn't work with certain views and I have had to use the left button instead:
Also, you can try setting B's button item instead of A:
try not backBarButtonItem but leftBarButtonItem instead
for me it works like a charm. And don't forget that you didn't release this button - and it can cause memory leak. So you can add autorelease when you assign you button or make it like this
In the Xcode documentation, it states that the backBarButtonItem target and action should be set to nil. So even if you do set it, it's probably a good bet that it will be ignored. You could check out the link below to add custom behaviour to the back button.
Custom Action on Back Button Item
Or you could just do the following in viewControllerB:
Then also add this to viewControllerB
The above method will find the RootViewController and send it the backButtonClicked message. It will then pop the current view controller, which should allow you to emulate the backBarButtonItem. Also you can change which view controller you want to send the message by changing the value in the objectAtIndex method.