前提・実現したいこと
TableViewのcellをタップをした時に、画面遷移&値渡しをしたいです。
発生している問題・エラーメッセージ
Cellをタップした時に落ちてしまいます。
let vcBagDetails = segue.destination as!ViewControllerBagDetails
のところに
Thread 1: signal SIGABRT
というエラーが出てしまいます...
該当のソースコード
Swift
1class ViewControllerBag: UIViewController, UITableViewDelegate, UITableViewDataSource { 2 3var cellIndex = "" 4 5override func viewDidLoad() { 6 } 7 8 func numberOfSections(in tableView: UITableView) -> Int { 9 return 1 10 } 11 12 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 13 //セルの個数を指定するデリゲートメソッド(必須) 14 return DBCells.count 15 } 16 17func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 18 print("(indexPath.row)番目のcellがタップされた") 19 // セルの選択を解除 20 tableView.deselectRow(at: indexPath, animated: true) 21 //(indexPath.row)を入れる 22 cellIndex = DBImageArray[(indexPath.row)] 23 //BagDetailに遷移 24 performSegue(withIdentifier: "BagDetails", sender: nil) 25 } 26 27 override func prepare(for segue:UIStoryboardSegue, sender: Any? ) { 28 if segue.identifier == "BagDetails" { 29 let vcBagDetails = segue.destination as!ViewControllerBagDetails 30 vcBagDetails.cellIndex2 = cellIndex 31 } 32 }
プログラムの一部を見やすいように省いています
補足情報
Xcode 11.2.1
シュミレーター iPhone 8
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/30 10:32
2020/01/30 10:35