在Swift中显示和关闭模式视图控制器 [英] Display and dismiss a modal view controller in Swift

查看:132
本文介绍了在Swift中显示和关闭模式视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当按下一个按钮时,我想使用模态过渡样式CoverVertical在两个视图控制器之间进行筛选,然后将其关闭.关于如何在目标C中执行操作的信息很多,但是在Swift中找不到任何好的信息.到目前为止,我已经做到了,但是我认为这是不正确的:

When a button is pressed I want to segue between two view controllers by using a Modal Transition style CoverVertical and then dismiss it. There is allot of info out there for how to do it in objective C but can't find any good info in Swift. So far I've done this but I don't think it's correct:

 @IBAction func insertStatus(sender: UIButton) {

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

    }

我正在使用的Dismiss也不起作用:

The Dismiss I am using like so does not work either:

@IBAction func statusSaved(sender: UIBarButtonItem) {

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

推荐答案

Swift 5:

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

dismiss(animated: true, completion: nil)


Swift 2.2:


Swift 2.2:

self.presentViewController(true, completion: nil)

隐藏/关闭视图控制器:

Hide/dismiss a view controller:

self.dismissViewControllerAnimated(true, completion: nil)

这篇关于在Swift中显示和关闭模式视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆