的TableView细胞错误 - 的iOS /斯威夫特
问题描述:
我已经运行的tableView的cellForRowAtIndexPath当这个错误:的TableView细胞错误 - 的iOS /斯威夫特
致命错误:意外发现零而展开的可选值
我不明白,我已经正确分配标识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)
}
注: =>我这样称呼新视图,因为我有一个自定义单元格,而且我无法从故事板中调用它。
感谢
编辑:在该行的错误:
let cell = tableView.dequeueReusableCellWithIdentifier("CellDataflow") as UITableViewCell
答
难道你不需要索引路径吗?
所以:
let cell = tableView.dequeueReusableCellWithIdentifier("IDENTIFIER", forIndexPath: indexPath) as UITableViewCell
答
我不是斯威夫特专家,但我查了一下资料,该方法返回一个可选值:
func dequeueReusableCellWithIdentifier(_ identifier: String) -> AnyObject?
也许它是返回nil
,请尝试使用as?
而不是as
并检查nil
。
答
let cell = tableView.dequeueReusableCellWithIdentifier("CellID", forIndexPath: indexPath) as UITableViewCell
我认为这将有助于你...
嗨感谢您的回答。 但它不是。 在各种测试中,我意识到我记得伤害了新观点。 我试图解释我的机构: - 我有一个自定义单元格的列表。当我点击这个单元格时,我希望你用一个列表进入一个新的视图,但这次单元格不是自定义的。 可能是错误的电话,因为它似乎总是在旧的视图上工作时,我上课MainTVC – uynva 2014-11-03 15:16:36
我不知道我明白你的意思是“始终工作在旧视图”。 – F1ank3r 2014-11-03 15:33:41