简体   繁体   English

删除导航视图的“堆栈” Xcode swift

[英]deleting a 'stack' of navigation views Xcode swift

The Link below shows my Storyboard and I think my problem is a lot easier to understand with the image. 下面的链接显示了我的情节提要,我认为使用图像更容易理解我的问题。 My tabBarController manages a tab which is embedded in a navigationController. 我的tabBarController管理嵌入在navigationController中的选项卡。 UIButton "start" leads to the next view by a show segue (blue arrow). UIButton“开始”通过show segue引导到下一个视图(蓝色箭头)。 On this view a bar button item leads to the last viewController again with a show segue (green arrow). 在此视图上,带有显示按钮(绿色箭头)的条形按钮项再次通向最后一个viewController。 From the last view controller i want to go back to my initial one, again by a bar button item (black arrow). 我想从最后一个视图控制器回到我的第一个视图控制器,再一次按下一个条形按钮项(黑色箭头)。 But now there is the Problem, that my initial view controller shows a "back button" on the top left (of course, because by the black arrow the initial view is just added to the navigation stack, right?!). 但是现在有一个问题,我的初始视图控制器在左上方显示了“后退按钮”(当然,因为通过黑色箭头,初始视图只是添加到了导航堆栈中,对吧?!)。 I solved this by going back to the tab bar controller (red arrow). 我通过回到标签栏控制器(红色箭头)解决了这个问题。 Now there is no "back" button any more but now i am wondering if there isn't like a stack of my navigation views still existing in the background and wasting memory or something like that. 现在不再有“后退”按钮了,但是现在我想知道是否还不存在我的导航视图堆栈仍然在后台并且浪费内存之类的东西。 How can i delete this stack or is it even existing? 我该如何删除该堆栈甚至它已经存在? (maybe i got this completely wrong) Or is there even a better way to go back to my first view? (也许我完全错了)还是有更好的方法可以回到我的第一个视图?

Sorry for the unprofessional description of my problem but i just started coding so i don't have the right words for some of the issues yet. 抱歉,我对问题的描述不专业,但我刚刚开始编码,因此对于某些问题我还没有合适的词。

thank you so much! 非常感谢!

我的情节提要看起来像这样

If I understood it correctly, you want your last view controller to navigate to the initial view controller of the navigation stack. 如果我正确理解,则希望最后一个视图控制器导航到导航堆栈的初始视图控制器。 On your last view controller, you can add this to your code: 在最后一个视图控制器上,您可以将其添加到代码中:

       override func viewDidLoad() {
    super.viewDidLoad()
    //this will add a button to top right of the nav bar, 
    //change "ButtonName" to a title you want
    //this button will call the blackArrow function
    self.navigationItem.rightBarButtonItem = UIBarButtonItem (
        title: "ButtonName", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.blackArrow))
}


func blackArrow() {
//this function navigates to the initial view controller of the navigation controller
if let navigationController = self.navigationController {
    navigationController.popToRootViewController(animated: true)

    }
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM