Navigationbar title and back button name are same?

前端 未结 5 925
傲寒
傲寒 2020-12-17 03:50

I created one title for navigationbar in my storyboard project ,but when I moved to next viewcontroller the back button shows the same name as my previous navigationbar(Main

5条回答
  •  清歌不尽
    2020-12-17 04:33

    Just do it in this way , one of the easiest way I did find till now :

    Create a custom back button and add it into the Navigation Bar left button item property :

    - (void)viewDidLoad
    {
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *backBtnImage = [UIImage imageNamed:@"Backnavigation.png"]  ; // Here set the back button image
    [backBtn setBackgroundImage:backBtnImage forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(handleBack:) forControlEvents:UIControlEventTouchUpInside];
    backBtn.frame = CGRectMake(0, 0, 24, 24);
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;
    self.navigationItem.leftBarButtonItem = backButton;
    }
    
    
    //Handle the Back Button Event
    - (void) handleBack:(id)sender
    {
        // do your custom handler code here
        [self.navigationController popViewControllerAnimated:YES];
    }
    

    Also, doing this way, you don't need to change the title of NavigationBar every-time.

    Here is the Back Button for your reference : enter image description here

提交回复
热议问题