简体   繁体   English

iOS / Swift:在视图控制器之间快速移动

[英]iOS/ swift : moving between view controllers in swift

suppose I have a MainTabBarController, from one of it's tabs, I go to FirstViewController, then from FirstViewController, I go to SecondViewController (all with present modally), in SecondViewController when user hits cancel button, I want to go back to MainTabBarController, without showing FirstViewController, can I do this without NavigationController? 假设我有一个MainTabBarController,从其中一个选项卡转到FirstViewController,然后从FirstViewController转到SecondViewController(全部以模态形式出现),在SecondViewController中,当用户单击“取消”按钮时,我想返回MainTabBarController,但不显示FirstViewController,我可以在没有NavigationController的情况下做到这一点吗? cus I have no NavigationController in current version of my code and it will cost me many changes :( cus我在当前版本的代码中没有NavigationController,这将花费我很多更改:(

in your SecondViewController you can call below code on tap of cancel button, which gets the presentingViewController of SecondViewController -> presentingViewController of FirstViewController which is a TabBarController and call dismiss on it. 在您的SecondViewController您可以在点击“取消”按钮时调用以下代码,这将获取SecondViewControllerpresentingViewController > FirstViewController presentingViewController ,它是一个TabBarController并对其调用dismiss

@objc func dismiss(_ button: UIButton) {
    self.presentingViewController?.presentingViewController?.dismiss(animated: true)
}

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

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