Add another button next to the “back” button on th

2019-02-08 13:00发布

问题:

I've tried this for hours but I still cannot solve it. When using UINavigationController and push a new view controller on top, I got a free "back" button on the left of the navigation bar. I want another button just next to it (to show a popover menu). I wonder what is the correct way to do that. Or I have to hide the free back button and make the same one by myself? If that's the case, I also need to pop the current view controller when pressing my own back button, right?

Thanks for your help.

回答1:

As stated by steipete in the comment to the question, this is possible starting from iOS 5. You can use

self.navigationItem.leftItemsSupplementBackButton = YES;

and then you just need to add an UIBarButtonItem as leftButton to get a second button after the back button

UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithTitle:@"Second" style:UIBarButtonItemStylePlain target:self action:@selector(yourAction)];
self.navigationItem.leftBarButtonItem = secondButton;