todoアプリでtableViewクラスを使っています。
セルを削除したいのですがどの変数を指定すれば良いのかよくわかりません。。
【エラー内容】 Use of unresolved identifier 'TodoCell'
import UIKit // classの継承 class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { // 表示するcellの数を宣言 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // todoリスト分だけ表示する return TodoKobetsunonakami.count } // 表示するCellの中身を決める func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // 変数を作る let TodoCell : UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "TodoCell", for: indexPath) // 変数の中身を作る TodoCell.textLabel!.text = TodoKobetsunonakami[indexPath.row] // 戻り値も設定 return TodoCell } // セルの編集を許可 func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true } // セルの削除 func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == UITableViewCell.EditingStyle.delete{ TodoCell.remove(at : indexPath) // ←ここでエラー出ます。 tableView.deleteRows(at : [indexPath as IndexPath], with: UITableView.RowAnimation.automatic) } } override func viewDidLoad() { super.viewDidLoad() if UserDefaults.standard.object(forKey: "TodoList") != nil{ TodoKobetsunonakami = UserDefaults.standard.object(forKey: "TodoList") as! [String] } } override func didReceiveMemoryWarning() { didReceiveMemoryWarning() } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/04/15 11:02
2020/04/15 11:08
退会済みユーザー
2020/04/15 11:24
2020/04/15 11:42