2016-04-26 5 views
0

私は次のようにCSwift Segueを使用してView Controllerにデータを渡す方法は?

からのデータを渡すこの enter image description here

のようにやりたい:Aでいくつかの文字列をキーイング、そしてBへ]ボタンをクリックし、Cへ]ボタンをクリックします。

Cのラベル

でshow文字列私はこの

元のようないくつかの通過データを見つける:aクラスで

let bController = segue.destinationVieController

bController.string = "xxx"

しかし、それはちょうどAからB からCへのデータはどうすればよいですか?AからCにデータを渡すべきですか?私はちょうどBAを検索するため

は今、私はこの作業を完了するためにNSNotificationCetnerを使用しますが、私はそれは本当に簡単だ場合セグエ閉鎖

を使用する方法を学びたい、私のキーワード

を教えてください。.. 。

ありがとう!

+0

まずBで文字列 "xxx"を取得します。これで同じ "xxx" BをCに渡します。 –

+0

NSUserDefaultsを使用して、任意のビューから利用可能で更新可能な値を格納しました。また、次回に利用可能な値を開いたときにアプリが終了した場合でも、それらは保持されます。これは、値を次のビューに渡してから次のビューに渡すほうが簡単です – Mych

答えて

1

あなたは

文字列がある
let cController = segue.destinationVieController 

cController.string = string 

以下のようなセグエを使用してコントローラB.パスになりましたB-> Cから同じ文字列を文字列を持っているので、あなたは、セグエを使用してA-> Bからの文字列を渡していますあなたはすぐにB-からセグエを実行することができA-からsegueing中に値を割り当てたコントローラーB内の変数> B

0

> CのYていることを確認してくださいセグエ

//VCA 
override func prepareForSegue(segue : UISegue, sender: AnyObject?) { 

    if segue.identifier == "AtoB" { 
     //Cast destination VC as a your B VC 
     let bVC = segue.destinationViewController as! BVC 
     //Set b's .string property to the string property you're going to send to c 
     bVC.string = self.string 
     //perform the segue that goes from b to c 
     bVC.performSegueWithIdentifier("BtoC") 

    } 

} 
//VCB 
override func prepareForSegue(segue : UISegue, sender: AnyObject?) { 

    if segue.identifier == "BtoC" { 
     //Cast destination VC as a your C VC 
     let cVC = segue.destinationViewController as! CVC 
     //Set c's .string property to the string property that you now go from 
     cVC.string = self.string 

     //Now you will have segue'd to C passing the string you got from a 
    } 

} 

の準備私たちのsegue.identifierはあなたがストーリーボードで設定したものと一致します。

関連する問題