在Swift中关闭并呈现视图控制器 [英] Dismiss and Present View Controller in Swift

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

问题描述

您好我正在尝试提供一个viewcontroller并关闭我当前的模态视图,但此代码无法正常工作

Hi I'm trying to present a viewcontroller and dismiss my current modal view but this code is not working

self.dismissViewControllerAnimated(true, completion: {
    let vc = self.storyboard?.instantiateViewControllerWithIdentifier("OrderViewController")
    self.presentViewController(vc!, animated: true, completion: nil)
})

反之亦然,在presentviewcontroller的完成块上也不起作用

vice versa is not working too on completion block of presentviewcontroller

编辑:替换vc!自我

推荐答案

你必须得到提供self(当前ViewController)的viewController。如果该视图控制器是rootViewController,您可以使用如下,如果不是该查询它基于您查看控制器层次结构。

You have to get the viewController which presented the self (current ViewController). If that view controller is rootViewController that you can use as below, if not that query it based on you view controller hierarchy.

if let vc3 = self.storyboard?.instantiateViewControllerWithIdentifier("vc3") as? ViewController3 {
    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    appDelegate.window?.rootViewController!.presentViewController(vc3, animated: true, completion: nil)
}

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

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