UINavigationController Back button title always sh

2019-07-18 06:38发布

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

4条回答
戒情不戒烟
2楼-- · 2019-07-18 07:00

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.

查看更多
萌系小妹纸
3楼-- · 2019-07-18 07:08

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];
查看更多
Animai°情兽
4楼-- · 2019-07-18 07:10

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];
}
查看更多
姐就是有狂的资本
5楼-- · 2019-07-18 07:22

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];
查看更多
登录 后发表回答