2016-04-26 26 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与您在故事板中设置的内容相匹配。

相关问题