导航控制器"后退按钮"文字:提出Modally

时间:2012-04-03 18:04:55

标签: objective-c ios uinavigationcontroller uibarbuttonitem modalviewcontroller

我正在创建一个视图控制器数组,将它们添加到UINavigation控制器,然后以模态方式呈现它们。

但是,我无法将每个视图中的“后退”按钮设置为“后退”一词以外的任何内容。

这是代码:

//The View Controllers and Array
VC1 *vc1 = [[VC1 alloc] initWithNibName:@"VC1" bundle:nil];
VC2 *vc2 = [[VC2 alloc] initWithNibName:@"VC2" bundle:nil];
VC3 *vc3 = [[VC3 alloc] initWithNibName:@"VC3" bundle:nil];
NSArray * viewControllers = [NSArray arrayWithObjects:vc3, vc2, vc1, nil];

// Create the nav controller and set the view controllers.
UINavigationController*  theNavController = [[UINavigationController alloc]
initWithRootViewController:vc3];
[theNavController setViewControllers:viewControllers animated:NO];

// Display the nav controller modally.
[self presentModalViewController:theNavController animated:YES];

我在每个VC的init中尝试了以下内容:

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
barButton.title = @"Acknowledge Briefings Read";
self.navigationItem.backBarButtonItem = barButton; 

......但它不起作用。有任何想法吗?非常感谢。

另外,相关的,我理想的是喜欢以“前进”方向导航堆栈。这可能是使用导航控制器吗?

3 个答案:

答案 0 :(得分:1)

嘿,它可能适合你:

self.navigationController.navigationBar.backItem.title = @"Acknowledge Briefings Read"; 

此代码应该放在当前可见的viewController中。您应该在viewWillApear

中添加它

干杯

答案 1 :(得分:0)

你不能在init中以任何方式执行任何操作。您需要等待viewDidLoad(或willAppear或didAppear),因为在init中没有绘制任何内容(在导航控制器的情况下,前一个项目将受到影响)。

这是我做的(在viewDidLoad中):

UIBarButtonItem *doneButon = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneButtonPressed)];
[self.navigationItem setRightBarButtonItem:doneButon];

答案 2 :(得分:0)

后退按钮测试自动设置为位于堆栈顶部的UIViewController的title属性。因此,在每个视图控制器的viewDidAppear或viewDidLoad中,当将新视图推入堆栈时,将self.title设置为要在“后退”按钮中显示的文本。