Parse/Swift tableviewcell 问题 "binary operator '==' cannot be applied to operands of type cell and nil"
Parse/Swift Issue with tableviewcell "binary operator '==' cannot be applied to operands of type cell and nil"
我在 Parse/Swift 使用 Xcode 6.3 beta
时遇到问题
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath , object: PFObject) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! secTableViewCell
if cell == nil
{
cell = secTableViewCell(style: UITableViewCellStyle.Default , reuseIdentifier: "cell")
}
// Configure the cell...
cell.title.text = (object["exams"] as! String)
cell.img.image = UIImage(named: "109.png")
return cell
}
错误指向
if cell == nil
{
cell = secTableViewCell(style: UITableViewCellStyle.Default , reuseIdentifier: "cell")
}
二元运算符“==”不能应用于类型为 cell 和 nil 的操作数
cell
的类型是 secTableViewCell
而不是 secTableViewCell?
(Optional<secTableViewCell>
)。因为它不是可选的,所以它不能为零。
如果您需要测试 nil
,那么您想要
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as? secTableViewCell
问题是您永远不必测试 nil
。 "cell" 应始终为同一类型(在您的情况下应始终为 secTableViewCell
.
我在 Parse/Swift 使用 Xcode 6.3 beta
时遇到问题 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath , object: PFObject) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! secTableViewCell
if cell == nil
{
cell = secTableViewCell(style: UITableViewCellStyle.Default , reuseIdentifier: "cell")
}
// Configure the cell...
cell.title.text = (object["exams"] as! String)
cell.img.image = UIImage(named: "109.png")
return cell
}
错误指向
if cell == nil
{
cell = secTableViewCell(style: UITableViewCellStyle.Default , reuseIdentifier: "cell")
}
二元运算符“==”不能应用于类型为 cell 和 nil 的操作数
cell
的类型是 secTableViewCell
而不是 secTableViewCell?
(Optional<secTableViewCell>
)。因为它不是可选的,所以它不能为零。
如果您需要测试 nil
,那么您想要
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as? secTableViewCell
问题是您永远不必测试 nil
。 "cell" 应始终为同一类型(在您的情况下应始终为 secTableViewCell
.