[英]Navigation Controller “back button” text: Presented Modally
我正在創建一個視圖控制器數組,將它們添加到UINavigation Controller中,然后以模態形式呈現它們。
但是,我無法將每個視圖中“返回”按鈕的文本設置為除“返回”一詞以外的任何內容。
這是代碼:
//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的初始化中嘗試了以下方法:
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
barButton.title = @"Acknowledge Briefings Read";
self.navigationItem.backBarButtonItem = barButton;
...但是它不起作用。 有任何想法嗎? 非常感謝。
另外,相關地,我理想地希望以“前進”方向瀏覽堆棧。 使用導航控制器可以做到這一點嗎?
嘿,它可能對您有用:
self.navigationController.navigationBar.backItem.title = @"Acknowledge Briefings Read";
這段代碼應該放在當前可見的viewController中。 您應該將其添加到viewWillApear中
干杯
您不能在init中執行任何視圖操作。 您需要等待viewDidLoad(或willAppear或didAppear),因為init尚未繪制任何內容(對於nav控制器,前一項將受到影響)。
這是我的工作(在viewDidLoad中):
UIBarButtonItem *doneButon = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneButtonPressed)];
[self.navigationItem setRightBarButtonItem:doneButon];
后退按鈕測試會自動設置為位於堆棧頂部的UIViewController的title屬性。 因此,在每個視圖控制器的viewDidAppear或viewDidLoad中,將self.title設置為要在將新視圖推入堆棧時顯示在“后退”按鈕中的文本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.