Adding a UIBarButtonItem programmatically to UINavigationBar

前端 未结 4 868
执念已碎
执念已碎 2021-01-07 19:21

I dropped in a UINavigationBar in UIInterfaceBuilder. I present this view modally and just want a UIBackBarButton to return to my last

4条回答
  •  無奈伤痛
    2021-01-07 19:52

    Use below code snippet :

    //Add button to NavigationController
    UIBarButtonItem *backButton = 
     [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@“back”, @"")
                                      style:UIBarButtonItemStylePlain 
                                     target:self 
                                     action:@selector(goBack)];
    
    self.navigationItem.leftBarButtonItem = backButton;
    
    //Perform action on back Button
    - (void) goBack {    // Go back task over-here
    }
    

    Different style types available are :

    UIBarButtonItemStylePlain, UIBarButtonItemStyleBordered, UIBarButtonItemStyleDone
    

提交回复
热议问题