objective-c - 后退按钮文字没有改变

标签 objective-c

对于我的 View Controller 之一(扩展 UITableViewController),我需要将其后退按钮文本配置为“后退”。但是后退按钮仍然显示父 View Controller 的标题(默认)。

- (void)viewDidLoad
{
    ...
    self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
}

最佳答案

您需要在将类插入堆栈的 View Controller 上设置后退按钮,例如创建并推送您正在显示的类的 Controller

View Controller Programming Guide for iOS 的文档建议将 UINavigationItem 保存在 Navigation Item Stack 中,它为堆栈中的当前项目提供标题和按钮。

重要的(我在[]中加了位)

Although most of the navigation bar’s content is obtained from the topmost navigation item [in the navigation stack], a pointer to the back item [of the previous item in the stack] is maintained so that a back button (with the title of the preceding item) can be created.

查看 Configuring the Navigation Item Object 部分下的文档,有一个图表显示堆栈和指向顶部项目下方项目的 backItem堆。在您的情况下,堆栈中的顶部项目将引用您正在显示的类的 UINavigationItem,而 backItem 将是指向推送它的类的指针。

注意
看看文档中的那个部分,一张图片值一千字

关于objective-c - 后退按钮文字没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8250904/

相关文章:

iphone - AVAudioPlayer 关闭 iPod - 如何解决?

ios - linkedin 应用程序的自定义 URL 链接

objective-c - KVO 说 KVO 观察者已注册,即使它没有(或者是吗?)

iphone - 一个好用的iPhone应用程序使用xcode开发教程

iphone - 我们可以通过使用@try,catch机制来防止崩溃吗?如果错误是-[__ NSArrayM objectAtIndex:]:索引0超出了空数组的范围

iphone - 使用委托(delegate)模式时避免 EXC_BAD_ACCESS

ios - 即使应用程序关闭也运行时钟或计时器

iphone - 检索 NSData 时的 EXC_BAD_ACCESS

objective-c - 如何在 Cocoa WebView 中禁用 JavaScript?

ios - 如何在 swift 中使用 Weex ios sdk pragma #define WX_EXPORT_METHOD(method)?