Are the title of the navigation bar title and back button buttons the same?

I created one title for the navigation bar in my storyboard project, but when I moved to the next view manager, the back button displays the same name as the previous navigation bar title (main navigation bar). Can I set individual button names and names?

I tried the following code but it does not work? why?

 self.navigationItem.title=@"Recent Books";
self.navigationItem.backBarButtonItem.title=@"Back";
+5
source share
4 answers

According to the UINavigationItem class reference

" , " " . [...] " ", ( ) ".

, VC, VC

self.navigationItem.title=@"Recent Books";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Back"
                                   style:UIBarButtonItemStylePlain
                                   target:nil
                                   action:nil];
self.navigationItem.backBarButtonItem=backButton;
+19

, A → B

viewcontroller viewDidLoad

UIBarButtonItem *btn_Back = [[UIBarButtonItem alloc] initWithTitle:@"Back"
 style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem=btn_Back;

, "" viewcontroller B

+6

.

-(void)viewDidAppear:(BOOL)animated
{
    self.navigationController.navigationBar.backItem.title = @"back";
}

Objective-C

[[self.navigationController.navigationBar backItem] setTitle:@"back"];
+2

Just do it this way, one of the easiest ways I've found so far:

Create a custom back button and add it to the property of the element of the left navigation button:

- (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, by doing this, you do not need to change the title of the NavigationBar every time.

Here is the back button for your reference: enter image description here

+1
source

All Articles