Ios Tableview中的Swift3.0自定义行返回零
我一直在遵循苹果在开发者页面上的指导 文件TableViewController中的以下代码块给我带来了一些麻烦Ios Tableview中的Swift3.0自定义行返回零,ios,swift,uitableview,swift3,Ios,Swift,Uitableview,Swift3,我一直在遵循苹果在开发者页面上的指导 文件TableViewController中的以下代码块给我带来了一些麻烦 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cellIdentifier = "CoinTableViewCell" guard let cell =
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "CoinTableViewCell"
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? CoinsTableViewCell else {
fatalError("The dequeued cell is not an instance of MealTableViewCell.")
}
let coinrow = coins[indexPath.row]
cell.rowLabel.text = coinrow.name // error on this line
return cell
}
我得到一个运行时错误,发生在最后一行代码的第二行,声明
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
我使用断点发现cell.rowLabel
的值为零。但是我不知道为什么。自定义行的标识符为“CoinTableViewCell”。你知道怎么回事吗
您连接了rowLabel的插座了吗?是的,我连接了,在单元格的自定义控制器内,您正在将单元格转换为键入
CoinsTableViewCell
。然而,在fatalError语句中,您将其称为MealTableViewCell
。可能是rowLabel
是在MealTableViewCell
中定义的,而不是CoinTableViewCell
。忘记更改Apple示例代码中的文本-不过这只是一条字符串错误消息,MealTableViewCell在我的项目中不存在。不过接得不错!您尚未将rowLabel
插座连接到故事板单元格中的UILabel
插座。是否已连接rowLabel插座?是的,我已连接,在您正在将单元格强制转换为键入CoinsTableViewCell
的单元格的自定义控制器内。然而,在fatalError语句中,您将其称为MealTableViewCell
。可能是rowLabel
是在MealTableViewCell
中定义的,而不是CoinTableViewCell
。忘记更改Apple示例代码中的文本-不过这只是一条字符串错误消息,MealTableViewCell在我的项目中不存在。不过接得不错!您尚未将rowLabel
插座连接到情节提要单元中的UILabel
。