Add button to navigationbar programmatically

后端 未结 12 1996
日久生厌
日久生厌 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:27

    In ViewDidLoad method of ViewController.m

    UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(back)];
    
    [self.navigationItem setLeftBarButtonItem:cancel];
    

    "(back)" selector is a method to dissmiss the current ViewController

提交回复
热议问题