ViewControllerにcollectionViewを配置して特定のcellがタップされると設定したSegueにより他のViewControllerに遷移し、タップされたcellのデータが遷移先のViewControllerに投げるように作成しています。
以下の2つの関数(「データを格納する関数」と「遷移先のViewControllerにデータを渡す関数」)によりデータ自体は遷移先に送られていますが、「遷移先のViewControllerにデータを渡す関数」の何かしらの間違いにより初めてのタップ時には何もデータが送られなく、2回目以降のタップ時には1個前にタップしたセルのデータが送られてしまいます。この問題を解決する方法がありましたらよろしくお願いします。
以下2つの関数は同じclass(mainViewController.swift)にあります。
データを格納する関数
Swift
1func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 2//省略 3 self.give_indexPath = String(indexPath.row) 4 self.give_day = self.set_class_comma[indexPath.row] 5 self.performSegue(withIdentifier: "new_class", sender: nil) 6 7 8 9 }
遷移先のViewControllerにデータを渡す関数
Swift
1override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 2 if segue.identifier == "new_class" { 3 let vc = segue.destination as! new_class_ViewController 4 vc.receive_indexPath = self.give_indexPath 5 vc.receive_day = self.give_day 6 7 } 8 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/03 16:47