嗨,我使用表视图来选择取消选择单元格并获得所需的结果。但是当我检查的任意单元格,然后向下滚动,然后检查显示了太桌面视图在滚动单元格上创建多个accessoryType
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
errorText!.removeFromSuperview()
tableView.deselectRowAtIndexPath(indexPath, animated: false)
let cell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
let person = numberArray[indexPath.row]
if cell.accessoryType == .None {
cell.accessoryType = .Checkmark
selectedPeople.addObject(person)
}else if cell.accessoryType == .Checkmark {
cell.accessoryType = .None
selectedPeople.removeObject(person)
}
print("\(selectedPeople)")
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("commentCellss", forIndexPath: indexPath)
for object in cell.contentView.subviews
{
object.removeFromSuperview();
}
let text1:UILabel = UILabel.init(frame: CGRectMake(20, 10, 350, 30))
text1.font = UIFont.systemFontOfSize(23)
text1.text = nameArray[indexPath.row] as? String
cell.contentView.addSubview(text1)
let text2:UILabel = UILabel.init(frame: CGRectMake(20, text1.frame.origin.y+text1.frame.size.height , 350, 30))
text2.font = UIFont.systemFontOfSize(15)
text2.text = numberArray[indexPath.row] as? String
text2.textColor = UIColor.lightGrayColor()
cell.contentView.addSubview(text2)
let text3:UILabel = UILabel.init(frame: CGRectMake(0, text2.frame.origin.y+text2.frame.size.height+6 , 350, 1))
text3.font = UIFont.systemFontOfSize(15)
text3.backgroundColor = UIColor.darkGrayColor()
cell.contentView.addSubview(text3)
return cell
}
你必须维护,因为细胞 –
的resusability的选择,我应该怎么做,其他细胞....意味着我必须检查哪些单元格已经在索引路径中的单元格中检查行。 ? –
请先给出下面的答案...... !!它为我工作 –