【发布时间】:2015-10-27 11:49:36
【问题描述】:
使用以下代码,当我单击一个单元格以创建复选标记附件时,它每 12 行重复一次复选标记。关于为什么的任何想法?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as? UITableViewCell
cell?.textLabel = "\(indexPath.row)"
return cell!
}
func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
if let cell = tableView.cellForRowAtIndexPath(indexPath) as? UITableViewCell {
if cell.accessoryType == UITableViewCellAccessoryType.Checkmark
{
cell.accessoryType = UITableViewCellAccessoryType.None
}
else
{
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
}
}
return indexPath
}
【问题讨论】:
-
因为你正在使用 dequeueReusableCellWithIdentifier
-
Nakib 因为它是一个自定义的 UITableViewCell
-
@Nikab 没有问“你为什么使用 dequeueReusableCellWithIdentifier?”他们只是告诉你为什么会出现问题。
标签: ios swift uitableview