[英]How to add a Back button to a NavigationBar?
如何將后退按鈕添加到導航欄中? 我知道有一些相關的問題,但沒有一個有幫助。 我沒有使用情節提要,也沒有從Master Detail模板開始。 有設置可以做到這一點嗎? 還是按代碼添加? 如果是這樣,我需要什么代碼? 任何幫助表示贊賞! 謝謝!
您無需顯式添加后退按鈕。 當您將控制器推入UINavigationController時,該按鈕將自動添加。 也就是說,調用為:
[navigator pushViewController: controller animated: ...];
創建一個后退按鈕。
如果正確使用navigationController,默認情況下將顯示后退按鈕。 ViewControllers應該是這個
NavigationController> FirstViewController> SecondViewController
您將需要創建navigationController並以firstVC為根實例化。 從firstVC中,您可以按secondVC
,然后將存在后退按鈕。
將以下內容放入appDelegate application didFinishLaunchingWithOptions:
中將首先加載firstVC。 初始化窗口后放置它...
UIViewController *firstVC = [[UIViewController alloc] initWithNibName:@"firstVC" bundle:nil];
// any setupup of firstVC
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:firstVC];
[self.window setRootViewController:navCon];
然后在您的firstVC類中,如果您想推送secondVC
在firstVC.m中:
UIViewController *secondVC = [[UIViewController alloc] init];
[self.navigationController pushViewController:secondVC animated:YES];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.