使用未声明的类型tableViewCell Swift

时间:2015-02-22 03:27:12

标签: ios swift xcode6.1

有人能告诉我我错过了什么或做错了吗?

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {

    let cell = tableView.dequeueReusableCellWithIdentifier("chatCell", forIndexPath: indexPath) as
      tableViewCell

    cell.chatText.text = object.valueForKey("chatText") as String
    cell.chatText.numberOfLines = 0
    let score = object.valueForKey("count") as Int
    cell.count.text = "\(score)"
    cell.time.text = "\((indexPath.row + 1) * 3)m ago"
    cell.replies.text = "\((indexPath.row + 1) * 1) replies"
    return cell
}

tableViewCell上发生了错误,我已经在这几个小时了,但是不知道什么是错的。

1 个答案:

答案 0 :(得分:3)

错误是由tableViewCell既不是固有类型也不是您创建的类型引起的。您可能打算使用tableViewCellUITableViewCell或自定义类的单元格而不是PFTableViewCell。但是从错误来看,似乎tableViewCell从未被声明为类型。

根据您在问题下方的评论,很明显您实际上正在使用名为VoteTableViewCell的自定义单元格。因此,您应该将cell初始化为VoteTableViewCell;但要确保它是自定义PFTableViewCell而不是自定义UITableViewCell,因为您的cellForRowAtIndexPath方法会返回PFTableViewCell