我有导航 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/