2016-11-02 165 views
0

对于混淆标题感到抱歉,但这是我的问题。我做了从“superVC”(collectionviewcell)到“childVC”的继续,并且运行良好。那么我想再次从那个“childVC”继续到“secondChildVC”(这是所有的数据来自superVC)。可能吗?因为我在执行那个赛季时总是得到一个零值。segue并将数据从viewcontroller传递到viewcontroller到另一个viewcontroller

它是这样的:SuperVC - > ChildVC - > secondChildVC

这里是superVC SEGUE:

var destination = [DestinationData]() 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "DestinationDetailVC"{ 
     let detailVC = segue.destination as? DestinationDetailVC 
     if let data = sender as? DestinationData{ 
      detailVC?.destinationDetail = data 
     } 
    } 
} 

这里是第二个VC赛格瑞

var destinationDetail : DestinationData? 
@IBAction func goToMapOnPressed(_ sender: Any) { 
    let detail = destinationDetail 
    self.performSegue(withIdentifier: "DestinationMapVC", sender: detail) 
    print(detail) 
} 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "DestinationMapVC"{ 
     let detailVC = segue.destination as? DestinationMapVC 
     if let data = sender as? DestinationData{ 
      detailVC?.destinationMapDetail = data 
     } 
    } 
} 

感谢

+0

您可以使用导航控制器中的后退按钮进入前一个视图控制器。 –

+0

错误对不起,我的不好解释...我想继续,并将数据从ChildVC传输到secondChildVC,但ChildVC中的数据来自SuperVC。它的东西像SuperVC - > ChildVC - > secondChildVC,导致所有的数据来自superVC。 @AbhishekBiswas – RoccoBerry

+0

@RoccoBerry如果我正确理解你的问题,你可能想访问你的SuperVC和稍后在SecondChildVC中的一些数据。如果是这样,那么我建议你应该使用__si​​ngleton__。 – Adeel

回答

0

我认为你正在发送阵列DestinationData第一赛格,但里面如果数据是DestinationData种类,那么数据将被发送到下一个VC,但实际上,您发送的是DestinationData对象的数组,因此if条件失败,因此数据不是传递到childVC

这就是为什么你可能会在secondChildVC零,因为没有 childVC的数据。

因此,您可以修改条件来检查数组,因为destination包含数组类型的数据。或者从prepareSegue方法中删除条件。

代码:

//Write this code in to get that clicked object then pass that object in sender 
let destTemp = sender[your selected index] 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
     if segue.identifier == "DestinationDetailVC"{ 
      let detailVC = segue.destination as? DestinationDetailVC 
      if let data = sender as? DestinationData{ 
       detailVC?.destinationDetail = data 
      } 
     } 
    } 

希望它能帮助。

快乐编码...

相关问题