Add another button next to the “back” button on the left of a UINavigationBar

送分小仙女□ 提交于 2019-11-29 17:12:56

问题


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;


来源:https://stackoverflow.com/questions/6561366/add-another-button-next-to-the-back-button-on-the-left-of-a-uinavigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!