【问题标题】:Use of undeclared type tableViewCell Swift使用未声明类型的tableViewCell Swift
【发布时间】:2015-02-22 03:27:12
【问题描述】:

谁能告诉我我错过了什么或做错了什么?

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 上,我在这个问题上做了几个小时,但无法弄清楚是什么问题。

【问题讨论】:

  • tableViewCell 不是一个类型,除非你自己创建它...应该是 UITableViewCell
  • 是的,我先尝试过,但遇到了同样的错误。不熟悉这让我感到困惑。
  • 我有一个名为 'VoteTableViewCell' 的 tableviewcell 文件并将其放入,它消除了以前的错误,但现在返回单元格上有一个说不能转换为 'PFTableViewCell'
  • 哦,我明白了。您正在使用自定义单元格。确保它是自定义 PFTableViewCell 而不是自定义 UITableViewCell,因为您的 cellForRowAtIndexPath 方法返回一个 PFTableViewCell。
  • 只是让您知道,这不是导致您的错误的原因。错误是因为 tableViewCell 不是固有类型引起的......但很高兴你明白了......

标签: ios swift xcode6.1


【解决方案1】:

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

从问题下方的 cmets 可以看出,您实际上正在使用一个名为 VoteTableViewCell 的自定义单元格。因此,您应该将cell 初始化为VoteTableViewCell;但请确保它是自定义 PFTableViewCell 而不是自定义 UITableViewCell,因为您的 cellForRowAtIndexPath 方法返回 PFTableViewCell

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多