How to add a right button to a UINavigationController?

后端 未结 21 1190
不思量自难忘°
不思量自难忘° 2020-11-28 18:25

I am trying to add a refresh button to the top bar of a navigation controller with no success.

Here is the header:

@interface PropertyViewController          


        
21条回答
  •  广开言路
    2020-11-28 18:34

    Just copy and paste this Objective-C code.

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        [self addRightBarButtonItem];
    }
    - (void) addRightBarButtonItem {
        UIButton *btnAddContact = [UIButton buttonWithType:UIButtonTypeContactAdd];
        [btnAddContact addTarget:self action:@selector(addCustomerPressed:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:btnAddContact];
        self.navigationItem.rightBarButtonItem = barButton;
    }
    
    #pragma mark - UIButton
    - (IBAction)addCustomerPressed:(id)sender {
    // Your right button pressed event
    }
    

提交回复
热议问题