Make a custom back button for UINavigationController

后端 未结 3 2000
悲哀的现实
悲哀的现实 2020-12-17 04:41

I\'m developping an app for iOS 4.2+. I subclassed my UINavigationController to insert two UIImageView and make the navigation bar look custom. Eve

3条回答
  •  不思量自难忘°
    2020-12-17 05:38

    Let's say you have two ViewControllers, A and B, you're pushing B onto the stack when A is topmost, and you want to customize the back button that shows up when B is on top.

    Typically, the way to do this is to set ViewController A's navigationItem.backBarButtonItem.

    Instead, what you're doing is to give ViewController B a custom button on the left side of the navbar by setting its navigationItem.leftBarButtonItem.

    You've implemented that approach fine, except that even if you don't set ViewController A's navigationItem.backBarButtonItem, by default you still get a default back button as well. So that button is probably showing up on top of your custom back button.

    If you set ViewController B's navigationItem.hidesBackButton = YES then you shouldn't have any problem.

    And in the future, when you implement custom back buttons, you should do it by setting navigationItem.backBarButtonItem instead of navigationItem.leftBarButtonItem. The one adjustment you'll have to make is that with this approach, for example you would use ViewController A's navigationItem to change the back button that shows up when ViewController B is on top.

提交回复
热议问题