前提・実現したいこと
遷移先のViewに値を渡したいと考えています。
遷移元のTableViewに配置されているViewをタップした時に画面遷移するように実装しています。
遷移先ViewではContainerViewを使い、親のViewと子Viewにそれぞれ同じ値を渡しすようにしたく、親のViewには値を渡すことができましたが、子Viewに値を渡すコードを書いてみたところ下記のエラーがでてしまいました。
解決方法教えていただけないでしょうか。
よろしくお願い致します。
発生している問題・エラーメッセージ
Thread 1: Exception: "*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray"
該当のソースコード
Swift
1 @objc func didTapAddMatchInfo(_ sender: UIButton, forEvent event: UIEvent) { 2 let touch = event.allTouches?.first 3 let point = touch!.location(in: self.tableView) 4 let indexPath = tableView.indexPathForRow(at: point) 5 6 let postData = postArray[indexPath!.row] 7 8 for matchInfo in matchInfoArray { 9 if postData.matchInfoId == matchInfo.id { 10 // PostDataに保存されているMatchInfoのidと一致するものを次のviewに渡す 11 matchInfoToRelated = matchInfo 12 break 13 } 14 } 15 16 // viewがタップされた時のアクション 17 self.performSegue(withIdentifier: "toRelatedPosts", sender: self) 18 } 19 20 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 21 let relatedHomeViewController = segue.destination as! RelatedHomeViewController 22 relatedHomeViewController.matchInfoFromHomeVC = matchInfoToRelated 23 24 let relatedPostsViewController = relatedHomeViewController.children[0] as! RelatedPostsViewController 25 relatedPostsViewController.sortMatchInfo = matchInfoToRelated 26 27 print("DEBUG_PRINT matchInfoFromHomeVCに値を渡す (String(describing: matchInfoToRelated))") 28 29 self.dismiss(animated: true, completion: nil) 30 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/29 14:11 編集
2020/06/29 15:10