Clo*_*loy 5 objective-c uiviewcontroller ios segue swift
我打算解雇我的当前UIViewController和礼物给一个新的UIViewController。
我使用了以下代码
let newViewController: ViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
self.presentViewController(newViewController, animated: false, completion: {
self.dismissViewControllerAnimated(false, completion: nil)
})
Run Code Online (Sandbox Code Playgroud)
它给出了以下错误
2016 年 6 月 4 日 11:40:59.864 myApp[851:117649] 尝试
在转换时关闭演示控制器。(<_UIFullscreenPresentationController: 0x1703e6900>) 2016-06-04 11:40:59.878 ePassBook[851:117649] transitionViewForCurrentTransition 未设置,演示文稿控制器在演示过程中被关闭?(<_UIFullscreenPresentationController: 0x1703e6900>)
您首先需要解雇当前存在的内容viewcontroller,然后在只提供另一个内容之后,因为一次您不能提供两个viewcontrollers,所以您的代码应该是这样的,
self.dismissViewControllerAnimated(false) { () -> Void in
self.presentViewController(newViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
如果您正在使用navigation controller,则呈现或关闭 VCnavigation controller
按照评论中的要求更新:
举个例子,
你有三个视图控制器 A、B 和 C,当前呈现的 viewController 是 C。就像 A -> B -> C
现在你想解雇 C 并呈现新的 D,那么你必须实例化 B,因为你正在解雇 C,所以 self 没有任何意义。是零。
所以你应该举出 B 的例子,然后b介绍 Db
就像是,
self.dismissViewControllerAnimated(false) { () -> Void in
b.presentViewController(d, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
如果您使用导航控制器,那么它应该是这样的,
b.navigationController.presentViewCon.....
Run Code Online (Sandbox Code Playgroud)