2016-04-26 30 views
0

我想要做這樣的 enter image description hereSwift如何使用Segue在視圖控制器上傳遞數據?

從A傳送數據到C

這樣的:在A鍵控一些字符串,並單擊按鈕B,然後單擊按鈕C

C的標籤

我找到一些數據傳遞這樣

前顯示的字符串:

a

let bController = segue.destinationVieController

bController.string = "xxx"

但它只是A到B

我應該怎麼做才能將數據從A傳遞到C

現在,我用NSNotificationCetner來完成這項工作,但我想學習如何使用賽格瑞關閉

如果它真的很容易,請告訴我關鍵字

,因爲我只是搜索AB .. 。

謝謝!

+0

首先你在B上得到字符串「xxx」,現在你同樣把「xxx」B傳給C. –

+0

我已經使用NSUserDefaults來存儲從任何視圖可用和可更新的值。如果下次打開可用值時應用程序關閉,它們也會持續存在。這可能更容易,然後將值傳遞給下一個視圖,然後重新傳遞給下一個視圖 – Mych

回答

1

您是從A->從B->通過串B使用SEGUE,所以你現在有字符串控制器B傳遞相同的字符串下使用賽格瑞像下面

let cController = segue.destinationVieController 

cController.string = string 

其中字符串是在控制器B,而從A- segueing您已分配的值變量>乙

0

您可以立即從B-執行SEGUE>中攪拌賽格瑞準備

//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與您在故事板中設置的內容相匹配。

相關問題