![](/img/trans.png)
[英]I have view controllers in a navigation controller hierarchy, but only want the navigation bar on the first view controller - how do I do this?
[英]How do i handle navigation Back button view hierarchy?
這是問題所在
1)Rootview控制器 - MYAssetVC->嵌入了NavigationController,此處將按鈕推送到另一個Addfilevc。
2)Addfilevc具有dropdownTextfield它將推送到另一個vc有tableview選中的行將顯示在textfield中。
3)如果我從下拉文本字段中選擇另一個值,它將再次推送到vc,我將選擇。
導航欄后退按鈕將導航到我想要處理此視圖的所有視圖層次結構。 如果我去相同的視圖,它應該只返回一次到最近的訪問如何做到這一點。
因為我是iOS新手。 提出任何建議。
從1-> 2-> 3導航
導航backbtn 3-> 2-> 1
如果我像這樣導航1-> 2-> 3->后退3-> 2再次2-> 3后退3-> 2再次2-> 3
如果我現在使用返回導航它顯示我應該導航的所有路徑路徑,如1-> 2-> 3>和3-> 2-> 1,如果有任何次數我在2和3中執行操作。
1,2,3是視圖控制器。
為后退按鈕創建一個IBAction並使用popViewController。
[self.navigationController popViewControllerAnimated:YES];
這將幫助您返回一頁。 你必須在有后退按鈕的所有頁面中寫這個,並且你想要返回一頁。
如果要直接返回rootViewController,請嘗試以下操作:
[self.navigationController popToRootViewControllerAnimated:YES];
如果你想彈出到堆棧中的任何特定viewController,你運行for循環來找到你要導航到的viewController,然后簡單地popToViewController,如下所示:
for (UIViewController *viewController in self.navigationController.viewControllers) {
if ([viewController isKindOfClass:[Addfilevc class]]) {
[self.navigationController popToViewController:viewController animated:YES];
}
}
希望這有助於清除您的概念。
編輯
在快速:
[self.navigationController popViewControllerAnimated:YES];
將成為self.navigationController?.popViewControllerAnimated(true)
[self.navigationController popToRootViewControllerAnimated:YES];
將成為navigationController?.popToRootViewControllerAnimated(true)
for循環如下:
如果您使用的是故事板,則可以使用此選項
let switchViewController = self.storyboard?.instantiateViewControllerWithIdentifier("view2") as ComposeViewController
self.navigationController?.pushViewController(switchViewController, animated: true)
和for-in循環
if let viewControllers = self.navigationController?.viewControllers {
for viewController in viewControllers {
self.navigationController!.popToViewController(viewController, animated: true);
}
}
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.