Value of type 'UITableViewCell' has no member 'postImageView'

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

New to iOS programming, I am getting the following error, I get it for 3 separate items, but solving one will solve them all.

I am getting the following error

Value of type 'UITableViewCell' has no member '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     } 

回答1:

The problem is that your cell object is a UITableViewCell and not a NewsTableViewCell. You need to dequeue a NewsTableViewCell that will actually have those properties on it.

Something like:

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


回答2:

try changing the following lines:

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


回答3:

tableView.dequeueReusableCell returns a UITableViewCell which (as the compiler tells you) does not have the properties you are asking for. You will have to cast it to the expected type NewsTableViewCell:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!