简体   繁体   English

如何使用 Foundation Xcode 更改 swift 中的 viewControllers

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM