Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

objective c - "back" text displayed in iOS7 UINavigationBar when view title is long

In my application,I need to show the previous viewController title to current viewController back title.

Its working perfectly in iOS6.

In iOS7,automatically the "back" title displayed other than the previous viewController title.

how to fix the issue in iOS7?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In iOS 7 you will not be allowed to set the back button's title to be any longer than 11 characters.

To avoid changing the title of the view controller, but to change the back button's title, you need to do this:

In the previous view controller (the one that will have the next view controller pushed on top of it) you need to set the backBarButtonItem like so:

/**
 *  Notifies the view controller that its view was added to a view hierarchy.
 *
 *  @param  animated                    If YES, the view was added to the window using an animation.
 */
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.title = @"My Title Can Be Long";

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

Now, when the next view controller is pushed on top of it, the back button will be whatever title you put in the backBarButtonItem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...