UINavigationController Back button title always show “Back”

泪湿孤枕 提交于 2019-12-24 03:55:11

问题


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];
}


来源:https://stackoverflow.com/questions/24553651/uinavigationcontroller-back-button-title-always-show-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!