gpt4 book ai didi

ios - tableviewcell "binary operator ' = =' cannot be applied to operands of type cell and nil"的解析/快速问题

转载 作者:IT王子 更新时间:2023-10-29 05:35:01 24 4
gpt4 key购买 nike

我在使用 Xcode 6.3 beta 时遇到 Parse/Swift 的问题

    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 . “单元格”应该始终是同一类型(在您的情况下,它应该始终是 secTableViewCell

关于ios - tableviewcell "binary operator ' = =' cannot be applied to operands of type cell and nil"的解析/快速问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28992785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com