'UITableViewCell'类型的值有没有成员'postImageView'

问题描述:

新的iOS编程,我收到以下错误,我得到它3个单独的项目,但解决之一将解决它们。'UITableViewCell'类型的值有没有成员'postImageView'

我收到以下错误

价值型“的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 
    } 

的问题是,你的目标是一个UITableViewCell而不是NewsTableViewCell。您需要将实际上具有这些属性的NewsTableViewCell出列。

喜欢的东西:

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

尝试改变下面几行:

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

... 

return cell 

tableView.dequeueReusableCell返回UITableViewCell其中(如编译器会告诉你)没有你所要求的性能。 你将不得不将它转换为预期的类型NewsTableViewCell

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