类型' UITableViewCell'的价值没有会员' postImageView'

时间:2016-09-15 18:54:46

标签: ios swift uitableview

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
    }

3 个答案:

答案 0 :(得分:1)

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

类似的东西:

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

答案 1 :(得分:0)

尝试更改以下行:

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

...

return cell

答案 2 :(得分:0)

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

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