tableViewでデータをセル上に乗せることには成功しましたがtableViewの編集機能を追加した結果エラーが出てしまいました。
追加したのは次の文です。
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
//削除の場合、配列からデータを削除する。 if( editingStyle == UITableViewCellEditingStyle.delete) { part.remove(at: indexPath.row) pass.remove(at: indexPath.row) userDefaults.removeObject(forKey: part[indexPath.row]) userDefaults.removeObject(forKey: pass[indexPath.row]) } //テーブルの再読み込み tableView.reloadData() }
ちなみに削除したデータはuserDefaultsを使って保存したデータです。
次のコードのlet cell:UITableViewCell=tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)の行でエラーが出てしまいました。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:UITableViewCell=tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)
cell.textLabel!.text=part[indexPath.row]
return cell
}
thread1:EXC_Bad_Instructionというエラーです。
セルの生成のコードでエラーが起きたということはセルを消したことによって本来の盤面との違いからエラーが起きたと思いtableView.reloadData()を記述したのですが変化ありません。
解決方法を教えてくださると幸いです
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。