Ios 在Swift中显示和取消模式视图控制器

Ios 在Swift中显示和取消模式视图控制器,ios,swift,segue,Ios,Swift,Segue,当按下按钮时,我想使用模式转换样式在两个视图控制器之间切换,然后关闭它。关于如何在目标C中做到这一点,有很多信息,但在Swift中找不到任何好的信息。到目前为止,我已经这样做了,但我不认为这是正确的: @IBAction func insertStatus(sender: UIButton) { var StatusVC: StatusViewController = StatusViewController() var modalStyle: UIModalTra

当按下按钮时,我想使用模式转换样式在两个视图控制器之间切换,然后关闭它。关于如何在目标C中做到这一点,有很多信息,但在Swift中找不到任何好的信息。到目前为止,我已经这样做了,但我不认为这是正确的:

 @IBAction func insertStatus(sender: UIButton) {

         var StatusVC: StatusViewController = StatusViewController()
    var modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CoverVertical
    StatusVC.modalTransitionStyle = modalStyle
    self.presentViewController(StatusVC, animated: true, completion: nil)

    }
我正在使用的“解雇”也不起作用:

@IBAction func statusSaved(sender: UIBarButtonItem) {

        self.dismissViewControllerAnimated(false, completion: { () -> Void in
            let usersVC: UsersViewController = self.storyboard?.instantiateViewControllerWithIdentifier("UsersViewController") as UsersViewController
       })
    }

您可以使用
UIViewController
中的
presentViewController:animated:completion:
dismissViewControllerAnimated:completion:
方法。请参见文件Swift 5:

present(UIViewController(), animated: true, completion: nil)

dismiss(animated: true, completion: nil)

Swift 2.2:

self.presentViewController(true, completion: nil)
隐藏/关闭视图控制器:

self.dismissViewControllerAnimated(true, completion: nil)

在Swift 3.0中关闭视图控制器的步骤

self.dismiss(animated: true, completion: {})
这很简单:

要使用swift 3.0关闭模态视图,请执行以下操作: 使用如下Api:

> @IBAction func dismissClick(_ sender: Any) {
>         dismiss(animated: true, completion: nil)
>         
>     }
目前:

> @IBAction func dismissClick(_ sender: Any) {
> present(UIViewController(), animated: true, completion: nil)
>         
>     }
有关更多详细信息,请访问:


在Swift 4中关闭视图控制器

dismiss(animated: true, completion: nil)

您是否尝试过使用故事板连接两个ViewController?不,我知道如何这样做,但这不允许您忽略它,是吗?我想用编程的方式来做。对不起,你能详细解释一下你想做什么吗?谢谢,我在VC1上。按下按钮时,我希望以模态方式呈现VC2(例如,以模态方式呈现)。然后,我想更新VC2中的某些内容(例如某些文本),完成后按save,它将关闭VC2。希望这能有所帮助……这是我试图实现的目标,但仅限于VC:谢谢我现在就到了,我已经编辑了我的问题,现在屏幕变黑了?将第二行修改为:
var StatusVC:UIViewController=StatusViewController()
。如果它不起作用,请将其替换为以下内容:
var StatusVC:StatusViewController=UIViewController()
。第一个仍然变为黑色,第二个要求输入名称?我不知道我的是什么?第一个是正确的。您是否记得在情节提要中将
UIViewController
命名为StatusVC(通过类标识检查器)?将其命名为StatusVC或StatusViewController?不管怎样,它还是会变黑。无法理解…如果您使用“隐藏”一词,会有点混乱,因为隐藏感觉对象仍然在那里,但您没有看到它。事实上,视图控制器从屏幕上消失后,其对象将被销毁,并且系统将回收其使用的内存。