Ios 如何从模态返回到主视图控制器

Ios 如何从模态返回到主视图控制器,ios,swift,xcode,Ios,Swift,Xcode,我对斯威夫特完全是个新手,有问题。因此,我为我的模态创建了一个导航控制器,并使用segue(Button2)从我的第一个视图控制器打开了我的模态。问题是,如何从模态视图返回到我的第一个视图控制器 您可以使用该方法关闭特定的ViewController 问题是您希望如何取消以模式显示的ViewController?有按钮吗?点击视图中的任意位置?点击一个小十字按钮 例如,如果您有一个UIButton要关闭: @IBAction func didTapClose(_ sender: UIButton

我对斯威夫特完全是个新手,有问题。因此,我为我的模态创建了一个导航控制器,并使用segue(Button2)从我的第一个视图控制器打开了我的模态。问题是,如何从模态视图返回到我的第一个视图控制器

您可以使用该方法关闭特定的ViewController

问题是您希望如何取消以模式显示的ViewController?有按钮吗?点击视图中的任意位置?点击一个小十字按钮

例如,如果您有一个UIButton要关闭:

@IBAction func didTapClose(_ sender: UIButton) {
      dismiss(animated: true, completion: nil)
 }
可以使用该方法关闭特定的ViewController

问题是您希望如何取消以模式显示的ViewController?有按钮吗?点击视图中的任意位置?点击一个小十字按钮

例如,如果您有一个UIButton要关闭:

@IBAction func didTapClose(_ sender: UIButton) {
      dismiss(animated: true, completion: nil)
 }
如果segue是“模式显示”,则可以通过以下行关闭视图控制器:

dismiss(animated: true, completion: nil);
navigationController?.popViewController(animated: true);
否则,如果segue是“show”,则可以通过以下行关闭视图控制器:

dismiss(animated: true, completion: nil);
navigationController?.popViewController(animated: true);
在这种情况下,请确保将ViewController嵌入到故事板中的navigationController中。如果您的ViewController未嵌入到navigationController中,并且您使用了showsegue,则应使用
Disclose(动画:true,完成:nil)
返回上一页

还有其他方法可以返回到以前的页面(例如)

祝你好运。

如果segue是“现在模式”,你可以通过以下行关闭视图控制器:

dismiss(animated: true, completion: nil);
navigationController?.popViewController(animated: true);
否则,如果segue是“show”,则可以通过以下行关闭视图控制器:

dismiss(animated: true, completion: nil);
navigationController?.popViewController(animated: true);
在这种情况下,请确保将ViewController嵌入到故事板中的navigationController中。如果您的ViewController未嵌入到navigationController中,并且您使用了showsegue,则应使用
Disclose(动画:true,完成:nil)
返回上一页

还有其他方法可以返回到以前的页面(例如)

祝你好运