运行tableView cellForRowAtIndexPath时出现此错误:
致命错误:解开Optional值时意外发现nil
我不明白,我已经正确分配了标识符ID,但错误地分配了..
这是我的代码:
当覆盖有趣的cellForRowAtIndexPath时:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellDataflow") as UITableViewCell
cell.textLabel.text = "This is a title."
return cell
}
这是我称之为视图的地方:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
….more code…
self.navigationController?.pushViewController(MainTVC(), animated: true)
}
注意=>我将这种方式称为新视图,因为我有一个自定义单元格,因此无法从情节提要中调用它。
谢谢
编辑:该行中的错误:
让单元格= tableView.dequeueReusableCellWithIdentifier(“ CellDataflow”)作为UITableViewCell
您还不需要索引路径吗?
所以:
let cell = tableView.dequeueReusableCellWithIdentifier("IDENTIFIER", forIndexPath: indexPath) as UITableViewCell
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句