Add button to navigationbar programmatically

后端 未结 12 1999
日久生厌
日久生厌 2020-12-04 12:03

Hi I need to set the button on right side, in navigation bar, programatically , so that if I press the button I will perform some actions. I have created the navigation bar

12条回答
  •  情书的邮戳
    2020-12-04 12:37

    Inside my UIViewController derived class, I am using the following inside viewDidLoad:

    UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] 
                                   initWithTitle:@"Flip"                                            
                                   style:UIBarButtonItemStyleBordered 
                                   target:self 
                                   action:@selector(flipView:)];
    self.navigationItem.rightBarButtonItem = flipButton;
    [flipButton release];
    

    This adds a button to the right hand side with the title Flip, which calls the method:

    -(IBAction)flipView

    This looks very much like you #3, but it is working within my code.

提交回复
热议问题