UIViewController has no member error when I'm

2019-09-11 01:17发布

I am trying to pass score data from my the main game view controller named ViewController.swift to another view controller named game_over_vc.swift. The storyboard id is game_over_vc. I used the instantiateViewControllerWithIdentifier to go to the game_over_vc when the game is over and show the score. There is a variable named score_text in the game_over_vc.swift where it should retrieve the data from the ViewController.swift. However, I got an error saying that the value type 'UIViewController' has no member 'score_text'. Where did I go wrong?

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条回答
登录 后发表回答