2016-11-02 9 views
0

残念ですが、ここは私の問題です。私は "superVC"(collectionviewcell)から "childVC"へのセグを行い、そのうまくいっています。その "childVC"から "secondChildVC"(すべてのデータがsuperVCのものです)に再びセグをしたいと思います。出来ますか?そのsegueを実行するときに私は常にゼロの値を得るためです。segueとviewcontrollerからviewcontrollerへのデータを別のviewcontrollerに転送する

このようなその何か:SuperVC - > ChildVC - > secondChildVC

ここではsuperVCセグエである:ここ

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

私の悪い説明に申し訳ありません...私はsegueとChildVCからsecondChildVCにデータを転送したいのですが、ChildVCのデータはSuperVCからです。 SuperVC - > ChildVC - > secondChildVCのようなものは、すべてのデータがsuperVCのものであるためです。 @AbhishekBiswas – RoccoBerry

+0

@RoccoBerry問題を正しく理解している場合は、おそらくSuperVC内のデータにアクセスし、後でSecondChildVCにアクセスしたいと思うかもしれません。もしそうなら、あなたは__singleton__を使うべきだとお勧めします。 – Adeel

答えて

0

です私はDestinationDataの配列を1番目のセグに送ると思いますが、内側にありますデータがDestinationData種類のクラスである場合、データはnextVCに送信されますが、実際にはDestinationDataオブジェクトの配列を送信しているので、if条件が失敗し、したがってデータは存在しません。 childVC

これは、secondChildVCのデータがないため、destinationDetailのデータがないため、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 
      } 
     } 
    } 

それがお役に立てば幸いです。

ハッピーコーディング...

関連する問題