Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigationbar title and back button name are same?

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 navigationbar) title.? Can i set separate title and back button names?

I tried following code but its not working ? why?

 self.navigationItem.title=@"Recent Books";
self.navigationItem.backBarButtonItem.title=@"Back";
like image 691
Naveen Avatar asked Apr 05 '13 08:04

Naveen


People also ask

How do I create a navigation bar in Swift?

Start with Navigation ControllerCreate a single view application in Xcode. Add two view controller into your storyboard. Create two different swift files for those view controllers and set identifiers for them. Take a button in each view controller, set constrain for them and customize as you want.


1 Answers

According to UINavigationItem Class Reference

"When this navigation item is immediately below the top item in the stack, the navigation controller derives the back button for the navigation bar from this navigation item. [...] If you want to specify a custom image or title for the back button, you can assign a custom bar button item (with your custom title or image) to this property instead."

So try this in your first VC from where you are pushing other VC

self.navigationItem.title=@"Recent Books";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Back"
                                   style:UIBarButtonItemStylePlain
                                   target:nil
                                   action:nil];
self.navigationItem.backBarButtonItem=backButton;
like image 108
βhargavḯ Avatar answered Sep 17 '22 17:09

βhargavḯ