前提・実現したいこと
swiftの参考書でサンプルアプリを作っている時に下の方にあるif分のlet = cell から始まるコードでエラーが出てしまいました。
発生している問題・エラーメッセージ
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
該当のソースコード
swift
1import UIKit 2 3class ShopListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{ 4 5 @IBOutlet weak var tableView: UITableView! 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 // Do any additional setup after loading the view, typically from a nib. 10 } 11 12 override func didReceiveMemoryWarning() { 13 super.didReceiveMemoryWarning() 14 // Dispose of any resources that can be recreated. 15 } 16 17 //Mark: - UITableViewDelegate 18 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{ 19 return 100 20 } 21 //Mark: - UITableViewDataSource 22 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 23 return 20 24 } 25 26 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ 27 if indexPath.section == 0{ 28 let cell = tableView.dequeueReusableCell(withIdentifier: "ShopListItem") as! ShopListItemTableViewCell 29 cell.name.text = "(indexPath.row)" 30 return cell 31 } 32 return UITableViewCell() 33 } 34 35}
試したこと
自分なりに調べてみて、何かがnilになっているのではないかということまでは考えたのですがいまいちわかりません
補足情報(FW/ツールのバージョンなど)
始めたばかりの初心者なので理解できていない用語や初歩的なことが多くありますので細かく解説していただけたら幸いです。
どうかみなさまの力を貸してください。
回答1件
あなたの回答
tips
プレビュー