当我使用instantiateViewControllerWithIdentifier时,UIViewController没有成员错误

时间:2016-02-28 05:14:15

标签: swift uiviewcontroller

我正在尝试将得分数据从名为ViewController.swift的主游戏视图控制器传递到另一个名为game_over_vc.swift的视图控制器。故事板ID是game_over_vc。我使用instantiateViewControllerWithIdentifier在游戏结束时转到game_over_vc并显示分数。 game_over_vc.swift中有一个名为score_text的变量,它应该从ViewController.swift中检索数据。但是,我收到一个错误,说明值类型' UIViewController'没有会员' score_text'。我哪里出错了?

func game_over () {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let game_over_vc = storyboard.instantiateViewControllerWithIdentifier("game_over_vc") as UIViewController

    game_over_vc.score_text = String(score) //the error is here

    self.presentViewController(game_over_vc as UIViewController, animated: false, completion: nil)
}

0 个答案:

没有答案