我知道這個問題已被問了很多次,但我檢查了各種答案中的所有可能的問題,它仍然無法正常工作。致命錯誤:意外地發現零,而解包可選值(刷卡導航)
我想自定義單元格添加到表格視圖,但出現此錯誤消息,並且應用程序崩潰:
Fatal error: unexpectedly found nil while unwrapping an Optional value
這裏是我加的表視圖控制器的代碼視圖:
import UIKit
class VC0: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var myTableView: UITableView!
var names = ["Artist name", "Artist Name", "Artist name", "Artist name", "Artist name", "Artist name"]
var cities = ["City", "City", "City", "City", "City", "City"]
var images = [UIImage(named: "avatar"), UIImage(named: "avatar1"), UIImage(named: "avatar2"), UIImage(named: "avatar3"), UIImage(named: "avatar4"), UIImage(named: "avatar5")]
override func viewDidLoad() {
super.viewDidLoad()
self.myTableView.registerClass(CustomCell.self, forCellReuseIdentifier: "cell")
self.myTableView.dataSource = self
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.myTableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
cell.photo.image = images[indexPath.row]
cell.name.text = names[indexPath.row]
cell.city.text = cities[indexPath.row]
return cell
}
}
該線路上出現的錯誤:
cell.photo.image = images[indexPath.row]
這裏是項目,如果你想看看完整的代碼:http://dl.dropboxusercontent.com/s/frhaniuw5e36xej/swipeViews%20-%20copie.zip?dl=0
擺脫你隱式解開的選項並強制解包。如果你需要[so]的幫助,你需要發佈你的實際代碼,而不是下載你的代碼的zip鏈接,這絕對是你的代碼,絕對不是病毒,絕對不會腐爛。 – nhgrif
謝謝,我要在這裏發佈代碼,只是檢查包括故事板在內的所有內容。 – TheoF