How to add a right button to a UINavigationController?

后端 未结 21 1178
不思量自难忘°
不思量自难忘° 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:49

    - (void)viewWillAppear:(BOOL)animated
    {    
        [self setDetailViewNavigationBar];    
    }
    -(void)setDetailViewNavigationBar
    {
        self.navigationController.navigationBar.tintColor = [UIColor purpleColor];
        [self setNavigationBarRightButton];
        [self setNavigationBarBackButton];    
    }
    -(void)setNavigationBarBackButton// using custom button 
    {
       UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"  Back " style:UIBarButtonItemStylePlain target:self action:@selector(onClickLeftButton:)];          
       self.navigationItem.leftBarButtonItem = leftButton;    
    }
    - (void)onClickLeftButton:(id)sender 
    {
       NSLog(@"onClickLeftButton");        
    }
    -(void)setNavigationBarRightButton
    {
    
      UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Show" style:UIBarButtonItemStylePlain target:self action:@selector(onClickrighttButton:)];          
    self.navigationItem.rightBarButtonItem = anotherButton;   
    
    }
    - (void)onClickrighttButton:(id)sender 
    {
       NSLog(@"onClickrighttButton");  
    }
    

提交回复
热议问题