【问题标题】:Value of type 'UITableViewCell' has no member 'postImageView'“UITableViewCell”类型的值没有成员“postImageView”
【发布时间】:2016-09-16 02:59:23
【问题描述】:

iOS 编程新手,我收到以下错误,我得到了 3 个单独的项目,但解决一个将解决所有问题。

我收到以下错误

“UITableViewCell”类型的值没有成员“postImageView”

// return how may records in a table
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.rssRecordList.count
    }

    // return cell
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> NewsTableViewCell {

        // collect reusable cell
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

        // find record for current cell
        let thisRecord : RssRecord  = self.rssRecordList[(indexPath as NSIndexPath).row]

        // set value for main title and detail tect
        cell.postImageView.image = UIImage(thisRecord.image)
        cell.postTitleLabel.text = thisRecord.title
        cell.authorLabel.text = thisRecord.storyDate


        // return cell
        return cell as! NewsTableViewCell
    }

【问题讨论】:

    标签: ios swift uitableview


    【解决方案1】:

    问题在于您的单元格对象是 UITableViewCell 而不是 NewsTableViewCell。您需要将实际上具有这些属性的 NewsTableViewCell 出列。

    类似:

    var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! NewsTableViewCell
    

    【讨论】:

      【解决方案2】:

      尝试更改以下行:

      let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! NewsTableViewCell
      
      ...
      
      return cell
      

      【讨论】:

        【解决方案3】:

        tableView.dequeueReusableCell 返回一个UITableViewCell,它(正如编译器告诉你的那样)没有你要求的属性。 您必须将其转换为预期的类型 NewsTableViewCell:

        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! NewsTableViewCell

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-04-07
          • 2016-03-11
          • 1970-01-01
          • 1970-01-01
          • 2021-06-17
          • 2018-01-15
          相关资源
          最近更新 更多