Hide the rightBarButtonItem of a navigation controller

前端 未结 3 1537
盖世英雄少女心
盖世英雄少女心 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:23

    If you need to hide/show the button based on some condition, try this:

    if (condition) { 
        self.navigationItem.rightBarButtonItem.title = @"";
        self.navigationItem.rightBarButtonItem.enabled = NO;
    } else {
        self.navigationItem.rightBarButtonItem.title = @"my button title";
        self.navigationItem.rightBarButtonItem.enabled = YES;
    }
    

    This way you don't have to save a reference to the button in a property or worry about wiring up the action on a new button.

提交回复
热议问题