前提・実現したいこと
初心者です。
レシピ一覧表を作成中です
とりあえず試しに3つの料理で作成しているところです。
シュミレーターを通して試してみると最後の
cell.textLabel!.text = TODO[indexPath.row]
return cell
の部分に以下のエラーコードが出ます。
多分ここの事で一人の回答者さんが一つ前の質問の方で、ellForRowAtでdequeueReuseableCellで取得した変数を捨てて、そのあとにメンバ変数のcellに値を設定していますが、もしかしてcellをreturnしていませんか?これはうまくいきません。dequeueReusableCellで取得したセルを返すようにしてください。と教えていただきましたが、私自身初心者で、このコードの書き方がイマイチ理解できません。どなたか親切な方、コードの方教えていただきましたら幸いです。よろしくお願いします。
発生している問題・エラーメッセージ
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
該当のソースコード
import UIKit class TableViewController:UIViewController,UITableViewDelegate,UITableViewDataSource{ @IBOutlet var MyTV: UITableView! @IBOutlet var cell: UITableViewCell! let TODO = ["カレー","肉ジャガ","野菜炒め"] override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return TODO.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let _:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell",for:indexPath) cell.textLabel!.text = TODO[indexPath.row] return cell } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。