【发布时间】:2016-04-27 07:43:51
【问题描述】:
//This is in the UITableViewCell class method
class func videoCellWithTableView(tableview:UITableView) -> OLVideoCell{
var cell = tableview .dequeueReusableCellWithIdentifier("OLVideoCell") as! OLVideoCell
// “!cell” Why you will be prompted “ Unary operator '!' cannot be applied to an operand of type 'OLVideoCell'”
if !cell {
cell = OLVideoCell(style: .Default, reuseIdentifier: "OLVideoCell")
cell.selectionStyle = .None
}
return cell
}
【问题讨论】:
-
因为这是 Swift 而
cell不是Bool。像这样写下你的条件:cell == nil. -
谢谢 但是会提示“'OLVideoCell'类型的值永远不能为零,不允许比较”
-
因为您强制将单元格转换为非可选类型。如果您期望
nil出现,请使用可选类型。
标签: swift