[英]How do I change viewControllers in swift with Foundation Xcode
I am trying to programmatically switch to another viewController scene when a certain event happens in Xcode for a MacOS app but am having trouble.当 MacOS 应用程序的 Xcode 中发生某个事件时,我试图以编程方式切换到另一个 viewController 场景,但遇到了麻烦。 The second view controller is in the same storyboard as the one I am trying to switch from.
第二个视图 controller 与我要切换的视图在同一个 storyboard 中。 I currently have
我目前有
let secondViewController = ViewController(nibName: "outcome", bundle: nil)
self.present(secondViewController, animator: true as! NSViewControllerPresentationAnimator)
but it seems to crash when the event is triggered:但是当事件被触发时它似乎崩溃了:
Could not cast value of type 'Swift.Bool' (0x2010043a8) to '__C.NSViewControllerPresentationAnimator' (0x2007787d0).
it also shows an error Thread 1: signal SIGABRT
on the second command where I self.present
它还显示错误
Thread 1: signal SIGABRT
on the second command where I self.present
you are trying to cast a bool
to NSViewControllerPresentationAnimator
您正在尝试将
bool
转换为NSViewControllerPresentationAnimator
try this code instead:试试这个代码:
let secondViewController = ViewController(nibName: "outcome", bundle: nil)
self.present(secondViewController, animator: true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.