iPhone:NavigationController 导航栏后退按钮文本

发布于 2024-08-18 00:54:39 字数 100 浏览 9 评论 0原文

当我将新的 ViewController 推到导航控制器堆栈上时,“后退”按钮是前一个控制器的标题。

如何将后退按钮中的文本更改为“后退”而不是默认的最后一个控制器名称?

When I push a new ViewController onto a navigation controller stack the "back" button is the Title of the previous controller.

How can I change the text in the back button to "Back" instead of the default name-of-last-controller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

忆伤 2024-08-25 00:54:39

这是使用除前一页标题之外的其他内容制作后退按钮的正确方法

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
barButton.title = @"Your Title";

self.navigationItem.backBarButtonItem = barButton; 

据我所知:

self.navigationItem.backBarButtonItem.title = @"Your Title";

将使前一页上导航栏的标题这不是您想要的。

This is the proper way to make a back button with something other than the previous' pages title

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
barButton.title = @"Your Title";

self.navigationItem.backBarButtonItem = barButton; 

Its to my understanding that:

self.navigationItem.backBarButtonItem.title = @"Your Title";

will make the Title of the navigation bar on the previous page this which is not what you want.

独行侠 2024-08-25 00:54:39

我知道,这个问题很老了,但我找到了一个很好的解决方案。

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
barButton.title = @"back";
self.navigationController.navigationBar.topItem.backBarButtonItem = barButton;

从 childView 开始工作!使用 iOS 7 进行测试。

I know, the question is very old, but I found a nice solution.

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
barButton.title = @"back";
self.navigationController.navigationBar.topItem.backBarButtonItem = barButton;

Works from childView! Tested with iOS 7.

旧时浪漫 2024-08-25 00:54:39

您需要在导航控制器上创建一个自定义按钮。将以下代码放入根视图控制器的 viewDidLoad 中:

UIBarButtonItem * tempButtonItem = [[[ UIBarButtonItem alloc] init] autorelease];
tempButtonItem .title = @"Back";

self.navigationItem.backBarButtonItem = tempButtonItem ;

通过设置根视图控制器上的导航栏按钮,推送的视图将显示相应的后退按钮。

You need to create a custom button on the navigation controller. Put the following code in the viewDidLoad in your Root View Controller:

UIBarButtonItem * tempButtonItem = [[[ UIBarButtonItem alloc] init] autorelease];
tempButtonItem .title = @"Back";

self.navigationItem.backBarButtonItem = tempButtonItem ;

By setting the navigation bar button on the Root View Controller, the pushed view shows the appropriate back button.

七度光 2024-08-25 00:54:39

您可以在推送新视图控制器之前更改导航控制器当前视图控制器的标题:

self.title = @"Custom Title";

[self pushViewController: newViewController ...];

and in the navigation controller's delegate class

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

if([viewController class] == [OldViewController class]) {

viewController.title = @"Your previous title";

}

}

You can change the title of the current view controller of the navigation controller before push the new view controller:

self.title = @"Custom Title";

[self pushViewController: newViewController ...];

and in the navigation controller's delegate class

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

if([viewController class] == [OldViewController class]) {

viewController.title = @"Your previous title";

}

}
摇划花蜜的午后 2024-08-25 00:54:39

您实际上可以在主视图控制器的 navigationItem 标题上设置标题。基本上每个 UIViewController 都有一个小存根 UINavigationItem,其中包含有关如何在 UINavigationController 内引用该视图的元数据。默认情况下,该元数据仅回退到 UIViewController 本身。

假设“self”是 UINavigationController 内可见视图的 UIViewController,请设置:

self.navigationItem.title = @"My Custom Title"

You can actually set the title on the main view controller's navigationItem's title. Basically each UIViewController has a little stub UINavigationItem which contains metadata about how that view should be referenced inside a UINavigationController. By default, that metadata just falls back to the UIViewController itself.

Assuming 'self' is the UIViewController of the view that's visible inside the UINavigationController, set:

self.navigationItem.title = @"My Custom Title"
我是有多爱你 2024-08-25 00:54:39

您可以通过在原始控制器的“viewWillDisappear”函数中设置后退按钮标题来实现此目的,如下所示:

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        //Set Title for this view
        self.navigationItem.title = "My Title"

}

override func viewWillDisappear(animated: Bool) {
        super.viewWillAppear(animated)
        //Set Title for back button in next view 
        self.navigationItem.title = "Back"
}

You can achieve this by setting the Back button title in the originating controller's "viewWillDisappear" function as follows:

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        //Set Title for this view
        self.navigationItem.title = "My Title"

}

override func viewWillDisappear(animated: Bool) {
        super.viewWillAppear(animated)
        //Set Title for back button in next view 
        self.navigationItem.title = "Back"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文