Tableview单元格迅速

时间:2015-10-31 08:45:48

标签: swift tableview

dequeReusableCellWithIdentifier期待字符串作为参数。但是,当我传递字符串时,它显示错误。

代码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell

if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "CELL")
}

    //we know that cell is not empty now so we use ! to force unwrapping

cell!.textLabel.text = "abc"
cell!.detailTextLabel.text = "1/2"


return cell }

问题

来自UITableViewCell的Downcast?到UITableViewCell只能打开选项。

1 个答案:

答案 0 :(得分:0)

dequeueReusableCellWithIdentifier的返回值声明为UITableViewCell?,因此只需删除类型转换。

var cell = tableView.dequeueReusableCellWithIdentifier("CELL") 

使用快速帮助或 - 点击符号查找声明总是有帮助的。