Hide the rightBarButtonItem of a navigation controller

前端 未结 3 1540
盖世英雄少女心
盖世英雄少女心 2021-02-19 03:45

Does anyone know how to hide a rightBarButtonItem of a UINavigationController? In my application, I have an edit button as a rightBarButtonItem

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-19 04:22

    To Hide the right button: self.navigationItem.rightBarButtonItem = nil;

    Now, to show it:

    1. If you setup the right button in your view controller by assigning it to self.editButtonItem then simply assign it again in order to show it:

      self.navigationItem.rightBarButtonItem = self.editButtonItem;

    2. If you setup the right button in your view controller by allocating and initing a UIBarButtonItem, then simply keep a reference to the UIBarButtonItem in your view controller, and assign it again when you need to show it.

提交回复
热议问题