2016-08-18 2 views
0

ビューコントローラ間で値を転送しようとしています。(Swift)ビューコントローラ間でデータを転送する

enter image description here

私はそれを動作させることができる午前:私は単にこのように、他のビューコントローラに私のボタンを接続したとき。私はprepareforSegueを無効にしています。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    var DestinationViewController : ViewTwo = segue.destinationViewController as! ViewTwo 
    DestinationViewController.scoretext = score.text! 
} 

すべて正常に動作しますが、他のコントローラをプログラムで開くと、値は転送されません。これは私がそのために使用しているコードです...

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let vc : ViewTwo = storyboard.instantiateViewControllerWithIdentifier("viewtwo") as! ViewTwo 
self.presentViewController(vc, animated: true, completion: nil) 

答えて

1

あなたがinstantiateViewControllerWithIdentifierを使用し、prepareForSegueは呼び出されません。インスタンス化の後でscoretextを割り当てる必要があります。

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let vc : ViewTwo = storyboard.instantiateViewControllerWithIdentifier("viewtwo") as! ViewTwo 
vc.scoretext = score.text! 
self.presentViewController(vc, animated: true, completion: nil) 
+0

ありがとうございました! – Ash

関連する問題