简体   繁体   English

如何处理导航后退按钮视图层次结构?

[英]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.

相关问题 我在导航控制器层次结构中具有视图控制器,但只希望第一个视图控制器上的导航栏-如何执行此操作? - 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 change the title of the "back" button on a Navigation Bar 如何通过Storyboard向导航栏添加后退按钮? - How do I add a Back Button to the Navigation Bar through Storyboard? 如何检查iOS中的视图层次结构? - How do I inspect the view hierarchy in iOS? 如何使用按钮返回到我的第一个视图 - How do I use a button to get back to my first view 如何设置自定义视图后退按钮 - How do I set a custom view back button 如何跳转到情节提要中的UIViewController并仍然保留导航层次结构? - How do I jump to a UIViewController in a storyboard and still retain the navigation hierarchy? 尝试处理 iOS 中的“后退”导航按钮操作 - Trying to handle “back” navigation button action in iOS 如何等待视图进入视图层次结构? - How do I wait for a view to come into the view hierarchy? 如何模拟Apple的“ Notes”并使用带有“后退”视图的导航控制器启动应用程序? - How do I emulate 'Notes' from Apple and start the app with a navigation controller with a 'back' view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM