prepareforseque麻烦在swift中显示我的变量

时间:2015-11-21 19:47:40

标签: swift

我正在尝试在我的viewcontroller 3中获取我的标签,以显示来自viewcontroller 1中文本框的整数输入的变量。 不幸的是,我不能让这个工作。

在我的第一个视图控制器中,我有:

@IBOutlet weak var shotAttempts: UITextField! //This is my  text box where the variable is typed I want to display in viewcontroller 3.

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    var DestViewController : nextlevelnow = segue.destinationViewController as! nextlevelnow
    DestViewController.shotsTaken = shotAttempts.text!

//nextlevelnow is my ID for my viewcontroller 3. 
}

然后在我的类我的viewcontroller 3我有代码:

  @IBOutlet var stats: UILabel! //This is the label I want to show my variable created in the shotAttempt textbox from my other viewcontroller.

  var shotsTaken = String()

  override func viewDidLoad() {
      super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.
  }


  @IBAction func check(sender: AnyObject) {
    print("check: \(shotsTaken)")
    stats.text = shotsTaken
  }

0 个答案:

没有答案