UINavigationController Back button title always sh

2019-07-18 06:17发布

问题:

I am developing an IOS application. I am using navigation controller. If I push to next page then back button title not shown previous page title in IOS 7. Back button title always "Back" in IOS 7. I set all pages titles in viewWillAppear, viewDidload like below. But it is not working.

self.navigationItem.title=@"Previous Page Title";
self.title  = @"Previous Page Title";

What can I set back button title with previous page title in IOS 7

Thanx

回答1:

If the title is large, back button shows back only.Try with short titles,like

self.title = @"Test";

if you want Long title , go for custom back button.



回答2:

In iOS 7 the back button length is constrained (I think to 11 chars). You can set a custom "back button title" like this, for example in viewDidAppear in the view controller with the long title (not the current view controller!):

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


回答3:

If you want to force to always have the back button, but still let the system create it for you (will handle "Back" localization, abbreviate the button to a single "<" if the current title is really long, etc), then just use an absurdly long back button title:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"                                                                                               really long never shown title"
                                                                         style:UIBarButtonItemStylePlain                                                                               
                                                                        target:nil
                                                                        action:nil];


回答4:

Try this code:

[[UIBarButtonItem alloc] initWithTitle:@"Your Title Here"
                         style:UIBarButtonItemStylePlain                                                                               
                         target:nil action:nil];

Or you can set an image for button like this:

UIBarButtonItem *barBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"arrow.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back:)];

self.navigationItem.leftBarButtonItem = barBtn;

And @selector method:

-(void)back:(id)sender{
  [self.navigationController popViewControllerAnimated:YES];
}