ios - Swift 在函数中连接到另一个 View Controller

标签 ios swift function segue xcode-storyboard

嗨,我已经多次尝试通过使用教程来连接到另一个 View Controller ,但它们不起作用。请有人给我关于如何设置和调用 Segue 到下一个 View Controller 的明确说明。请记住,此代码不会位于当前 View Controller 类中。

该函数在我的玩家死亡时运行,因此我希望出现另一个 View Controller 。其功能是:

 func playerHitSquare(player:SKSpriteNode, level1: Enemy){

    timer.invalidate()
    removeAllChildren()
}

我想要访问的 View Controller 名为 FinishViewController,其标识符为 Finish,当前 View 为 GameViewController。

最佳答案

如果您使用导航 Controller ,则可以调用

func popViewControllerAnimated(_ animated: Bool) -> UIViewController?

删除当前的 VC,然后

func pushViewController(_ viewController: UIViewController, animated animated: Bool)

将所需的 View Controller 添加到导航堆栈并使其处于事件状态。请记住,您可能需要向 View Controller 类的 viewDidLoad 或 viewDidAppear/viewDidDisappear 添加代码,具体取决于

关于ios - Swift 在函数中连接到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39538584/

相关文章:

c - 当我使用 printf() 函数在 C 中编写函数名时打印什么

mysql - 在存储函数中插入失败

ios - 在 iTunes Connect 中创建用户时出错 : Invalid Year

objective-c - NSDictionary 问题

arrays - 在 Swift 中处理多维对象数组

ios - 接收器没有标识符 swift 2 的 segue

ios - 快速使用 WhirlyGlobe-Maply

php - 有用函数的集合最好作为函数库保存还是应该转换为类?

ios - Swift:当struct具有默认的数组初始化时,JSONDecoder不会解码

ios - UILabel - 在展开可选值时意外发现 nil