swift 中的表格视图单元格
Tableview cell in swift
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 向下转换?到 UITableViewCell 只展开选项。
dequeueReusableCellWithIdentifier
的 return 值声明为 UITableViewCell?
所以只需删除类型转换。
var cell = tableView.dequeueReusableCellWithIdentifier("CELL")
使用 Quick Help 或 ⌘ - 单击符号查找声明总是有帮助的。
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 向下转换?到 UITableViewCell 只展开选项。
dequeueReusableCellWithIdentifier
的 return 值声明为 UITableViewCell?
所以只需删除类型转换。
var cell = tableView.dequeueReusableCellWithIdentifier("CELL")
使用 Quick Help 或 ⌘ - 单击符号查找声明总是有帮助的。