我在使用 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
。"cell"应始终为相同类型(在您的情况下,应始终为secTableViewCell
。