【发布时间】:2017-04-06 07:07:58
【问题描述】:
我在同一个 Collectionviewcell 上有两个 tableview。当我运行应用程序时,它在 tableview 的 cellforrowatindexpath 中崩溃,说:“致命错误:在展开可选值时意外发现 nil”
请在下面找到我的一些代码 -
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->
UITableViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier:
reuseIdentifier, for: indexPathOfCollectionView as IndexPath) as!
MyCustomCollectionViewCell
if(tableView == cell.graphTableView){
let cell:CustomGraphTableViewCell =
tableView.dequeueReusableCell(withIdentifier: "CustomGraphTableViewCell") as!
CustomGraphTableViewCell
return cell
}
else
{
let cell:MyCustomTableViewCell =
tableView.dequeueReusableCell(withIdentifier: "MyCustomTableViewCell") as!
MyCustomTableViewCell
cell.nameLabel.text = namesArray[indexPath.row]
return cell
}
}
任何人都可以提出解决方案。为什么会发生这种情况?解决方法是什么?
【问题讨论】:
-
你不能让
CollectionViewCell`` in TableViewcellForRowAt`方法出队。 -
你在这里强制解开“as!”检查您的所有单元格,因为现在它为零
-
@NiravD 如果我不在那里声明collectionview单元格,那么我该如何访问tableview?
-
@Vadim Kozak 好的。如果它为零,我该怎么做才能纠正它?
-
为什么你使用collectionview cell 而不是tableview cell? collectionview 单元格不能在 tableview 中作为单元格工作。
标签: ios iphone swift uitableview swift3