2016-09-15 91 views
0

新的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 
    } 

回答

1

的問題是,你的目標是一個UITableViewCell而不是NewsTableViewCell。您需要將實際上具有這些屬性的NewsTableViewCell出列。

喜歡的東西:

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

嘗試改變下面幾行:

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

... 

return cell 
0

tableView.dequeueReusableCell返回UITableViewCell其中(如編譯器會告訴你)沒有你所要求的性能。 你將不得不將它轉換爲預期的類型NewsTableViewCell

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

相關問題