iphone - 如何在 appdelegate 上更改后退按钮的文本

标签 iphone ios cocoa-touch uinavigationcontroller

我有导航 Controller ,我想更改 appdelegate 上的导航后退按钮文本。所以我想在 appdelegate 上更改每个 uiviewController 的后退按钮的文本。是否可以?

我写了以下代码,但它不工作。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    navigationController=[[UINavigationController alloc]initWithRootViewController:self.viewController];

    self.window.rootViewController =  self.navigationController;


    self.navigationController.navigationItem.backBarButtonItem =
    [[UIBarButtonItem alloc] initWithTitle:@"custom back text"
                                     style:UIBarButtonItemStyleBordered
                                    target:nil
                                    action:nil];  // didn't work


    [self.window makeKeyAndVisible];
    return YES;
}

最佳答案

您需要了解导航栏(有一个,由导航 Controller 拥有、管理和控制)和导航项(有很多,导航 Controller 堆栈中每个 View Controller 一个,由 View 拥有和控制)之间的区别 Controller )。所以你不能从你尝试的地方改变它。

相反,在每个 View Controller 中更改它或将导航 Controller 子类化(或充当其委托(delegate)),以便您可以在添加到堆栈时更改每个 View Controller 。

关于iphone - 如何在 appdelegate 上更改后退按钮的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17649825/

相关文章:

iphone - 核心图 - 防止缩放/缩放图以显示完整的轴范围

iphone - iOS 中的钥匙串(keychain)真的有效吗?

android - 如何设置 ScrollView 以适应 React Native?

ios - 发送到解除分配实例的 iPhone 消息

iphone - 锁定 ViewController 的方向

ios - UIView 的程序化 "fuzzy"样式背景

ios - iOS7键盘快捷键是如何实现的?

objective-c - 在远程通知中添加文本字段,iOS 8

iphone - 在 UIWebView 中显示图像

iphone - 使用 TouchXML 的 ASIHTTPRequest 示例