How do I add a left bar button without overriding the natural back button?

前端 未结 2 985
执笔经年
执笔经年 2021-01-17 22:08

I have a project that uses UIViewControllers embedded in navigation view controllers, so the back button is automatically set up for me whenever I segue into any detail of m

相关标签:
2条回答
  • 2021-01-17 22:46

    These two lines with do the trick. Set leftItemSupplementBackButton to true, and then add leftBarButtonsItems.

    self.navigationItem.leftItemsSupplementBackButton = true
    self.navigationItem.leftBarButtonItems = [barButton]
    
    0 讨论(0)
  • 2021-01-17 22:58

    By default, the leftItemsSupplementBackButton property is false. In this case, the back button is not drawn and the left item or items replace it. If you would like the left items to appear in addition to the back button (as opposed to instead of it) set leftItemsSupplementBackButton to true.

    @property(nonatomic) BOOL leftItemsSupplementBackButton
    

    you can use something like this

    navigationItem.leftBarButtonItem = editButton
    //or
    navigationItem.leftBarButtonItems = [editButton]
    
    self.navigationItem.leftItemsSupplementBackButton = true
    
    0 讨论(0)
提交回复
热议问题