guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifier", for: indexPath) as? MYVerticalCell else {
fatalError("Couldn't deque `Vertical Cell`")
}
cell.view.backgroundColor = .black
return cell
查看插座与电池连接
在解开可选值时意外发现nil
答案 0 :(得分:2)
首先使用标识符
创建自定义单元格的xib使用前注册单元格,使用以下示例
tableView.register(UINib(nibName: "custCell", bundle: nil), forCellReuseIdentifier: "custCell")
然后使用下面的“func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) - > UITableViewCell”
var cell = tableView.dequeueReusableCell(withIdentifier: "custCell") as? CustCell
if (cell == nil) {
cell = CustCell(style: UITableViewCellStyle.default, reuseIdentifier: "custCell"
}