找到 nil table 查看单元格
Found nil table view cell
我有一个二维数组:
var s = [["Maths"],["English"]]
cellPressed
是一个变量,用于查找在上一个视图中按下的所有工作的单元格
每次我这样做:
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let Cell: subjectTableViewCell =
tableView.dequeueReusableCellWithIdentifier("subjectCell") as! subjectTableViewCell
Cell.subjectName.text = s[cellPressed][indexPath.row]
return Cell
}
我得到:
fatal error: unexpectedly found nil while unwrapping an Optional value
尝试以下操作。您不应该强制展开单元格。
func tableView (tableView: UITableView, cellForRowAtIndexPath
indexPath: NSIndexPath) -> UITableViewCell
{
let Cell: subjectTableViewCell = tableView.dequeueReusableCellWithIdentifier("subjectCell") as? subjectTableViewCell ?? subjectTableViewCell()
Cell.subjectName.text = s[cellPressed][indexPath.row]
return Cell
}
只能是两件事。
- 您的手机号为零(说明您设置有误!)
- s[cellPressed][indexPath.row] 为零
实际上,我认为只有第一个是可能的,因为如果它超出范围,它实际上会崩溃,所以在访问它之前确保您的单元已完全配置!
我有一个二维数组:
var s = [["Maths"],["English"]]
cellPressed
是一个变量,用于查找在上一个视图中按下的所有工作的单元格
每次我这样做:
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let Cell: subjectTableViewCell =
tableView.dequeueReusableCellWithIdentifier("subjectCell") as! subjectTableViewCell
Cell.subjectName.text = s[cellPressed][indexPath.row]
return Cell
}
我得到:
fatal error: unexpectedly found nil while unwrapping an Optional value
尝试以下操作。您不应该强制展开单元格。
func tableView (tableView: UITableView, cellForRowAtIndexPath
indexPath: NSIndexPath) -> UITableViewCell
{
let Cell: subjectTableViewCell = tableView.dequeueReusableCellWithIdentifier("subjectCell") as? subjectTableViewCell ?? subjectTableViewCell()
Cell.subjectName.text = s[cellPressed][indexPath.row]
return Cell
}
只能是两件事。
- 您的手机号为零(说明您设置有误!)
- s[cellPressed][indexPath.row] 为零
实际上,我认为只有第一个是可能的,因为如果它超出范围,它实际上会崩溃,所以在访问它之前确保您的单元已完全配置!