How to add a right button to a UINavigationController?

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

    -(void) viewWillAppear:(BOOL)animated
    {
    
        UIButton *btnRight = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnRight setFrame:CGRectMake(0, 0, 30, 44)];
        [btnRight setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
        [btnRight addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *barBtnRight = [[UIBarButtonItem alloc] initWithCustomView:btnRight];
        [barBtnRight setTintColor:[UIColor whiteColor]];
        [[[self tabBarController] navigationItem] setRightBarButtonItem:barBtnRight];
    
    }
    

提交回复
热议问题