I’m working in Xcode 4.3.2 using storyboards. I’ve created a segue between two views by clicking on the button I want to create a segue and control+click+drag a connection to the next view controller. Of course this creates an automatic/default back button in the navigation bar in the next view controller. What I want to do is customize the look of this back button. SO, I looked around online and found this code:
self.navigationItem.hidesBackButton = YES;
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 4, 40, 40)];
[button setImage:[UIImage imageNamed:@"homeButton.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = back;
It works great to change the LOOK of the button, but the problem now is that when I click that button, Xcode throws an error: “unrecognized error sent to instance…”
Can anyone help me to figure out how to now add the proper functionality to my custom back button? Thanks.
Have you implemented the method
- (void)backAction?To make the back button behave as such with a navigation controller, A possible implementation could look like:
This may need to be tweaked depending on your app setup and what you want it to do when the button is pressed but it should be a good starting point