Well, figuring such thing was easy, I decided to get a custom action executed by my UIBarButtonItem once it’s pressed. Here’s the code:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"GET BACK!!!" style:UIBarButtonItemStylePlain target:self action:@selector(test)];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[self.navigationController pushViewController:appsViewController animated:YES];
Yet, even without adding any custom views, -test isn’t called at all (although the title change is applied).
As you can see, I’m applying these changes to the item right before I push the new view controller (else the title change wouldn’t even work).
I’ve searched a lot for an answer to this, but the only trouble people seem to be having is it not replying to an action once it has a custom view. So; what am I doing wrong?
You can’t set custom actions on back buttons. (Or, rather the action of the back button item is set to a internal one that does the back-behaviour.) If you want to do something when the user comes back to your view controller, consider doing it in
viewWillAppear:. You might need to keep track of whether you’re appearing after pushing a child view controller or appearing the first time, etc.