我是编码新手,所以不确定如何解决此错误:
private let cellReuseIdentifier = "ArticleViewCell"
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier) as? UITableViewCell
if cell == nil {
cell = ArticleViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: cellReuseIdentifier)
}
我收到此错误:
Downcast from 'UITableViewCell?' to 'UITableView only warps optionals; did you mean to use "!"?
我尝试将
?
更改为!
也会收到错误消息。 最佳答案
尝试
let cell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath) as! UITableViewCell
也不要忘记返回单元格。
return cell