[英]How do i handle navigation Back button view hierarchy?
Here is the problem 这是问题所在
1) Rootview controller - MYAssetVC-> Embedded with NavigationController here pushing for button to another Addfilevc. 1)Rootview控制器 - MYAssetVC->嵌入了NavigationController,此处将按钮推送到另一个Addfilevc。
2) Addfilevc Has dropdownTextfield It will push to another vc have tableview selected row will display in the textfield. 2)Addfilevc具有dropdownTextfield它将推送到另一个vc有tableview选中的行将显示在textfield中。
3)if i select another value from the dropdown textfield it will push to the vc again there i will select. 3)如果我从下拉文本字段中选择另一个值,它将再次推送到vc,我将选择。
Navigation bar back button will navigate to all my view hierarchy i want to handle this one. 导航栏后退按钮将导航到我想要处理此视图的所有视图层次结构。 if i go to same view it should navigate back only once that to the recent visit how to do this.
如果我去相同的视图,它应该只返回一次到最近的访问如何做到这一点。
As i am new to iOS. 因为我是iOS新手。 give any suggestion.
提出任何建议。
Navigation from 1->2->3 从1-> 2-> 3导航
navigation backbtn 3->2->1 导航backbtn 3-> 2-> 1
if i navigate like this 1->2->3-> backbutton 3->2 again 2->3 backbutton 3->2 again 2->3 如果我像这样导航1-> 2-> 3->后退3-> 2再次2-> 3后退3-> 2再次2-> 3
IF i navigate now using back it is displaying all my route path it should navigate like 1->2->3> and 3->2->1 if any number of times i perform actions in 2 & 3. 如果我现在使用返回导航它显示我应该导航的所有路径路径,如1-> 2-> 3>和3-> 2-> 1,如果有任何次数我在2和3中执行操作。
1,2,3 are view controllers. 1,2,3是视图控制器。
Create an IBAction for the back button and use popViewController. 为后退按钮创建一个IBAction并使用popViewController。
[self.navigationController popViewControllerAnimated:YES];
This will help you to go back one page. 这将帮助您返回一页。 You have to write this in all the pages where there is a back button and you want to go back one page.
你必须在有后退按钮的所有页面中写这个,并且你想要返回一页。
If you want to go back directly to rootViewController, try this: 如果要直接返回rootViewController,请尝试以下操作:
[self.navigationController popToRootViewControllerAnimated:YES];
And if you want to pop to any specific viewController in the stack, you run a for loop to find the viewController you want to navigate to and then simply popToViewController, like this: 如果你想弹出到堆栈中的任何特定viewController,你运行for循环来找到你要导航到的viewController,然后简单地popToViewController,如下所示:
for (UIViewController *viewController in self.navigationController.viewControllers) {
if ([viewController isKindOfClass:[Addfilevc class]]) {
[self.navigationController popToViewController:viewController animated:YES];
}
}
Hope this helps to clear your concept. 希望这有助于清除您的概念。
EDIT 编辑
In swift: 在快速:
The [self.navigationController popViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];
will become self.navigationController?.popViewControllerAnimated(true)
将成为
self.navigationController?.popViewControllerAnimated(true)
The [self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
will become navigationController?.popToRootViewControllerAnimated(true)
将成为
navigationController?.popToRootViewControllerAnimated(true)
And the for loop will be as below: for循环如下:
You can use this if you are using storyboard 如果您使用的是故事板,则可以使用此选项
let switchViewController = self.storyboard?.instantiateViewControllerWithIdentifier("view2") as ComposeViewController
self.navigationController?.pushViewController(switchViewController, animated: true)
And the for-in loop 和for-in循环
if let viewControllers = self.navigationController?.viewControllers {
for viewController in viewControllers {
self.navigationController!.popToViewController(viewController, animated: true);
}
}
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.