我有一个tableViewCell,它在单元格的accessoryType
中使用复选标记。我有一个函数将单元格的内容放入textField中,并在未选中时从文本字段中删除文本。TableView选中的单元格 - 选中的单元格在滚动不见时会消失并检查新的单元格
它似乎工作正常,但如果我检查一个单元格,并希望检查一个单元格不可见(IOW)我需要滚动tableView,被检查的单元格(现在不可见)似乎取消选中它自己(只有当我检查一个新的可见细胞)。
多重选择仅适用于可见细胞。
这里是我的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath)
let row = indexPath.row
cell.textLabel?.text = painArea[row]
cell.accessoryType = .None
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//selectedRow = indexPath
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let row = indexPath.row
let cell = tableView.cellForRowAtIndexPath(indexPath)
if cell!.accessoryType == .Checkmark {
cell!.accessoryType = .None
} else {
cell!.accessoryType = .Checkmark
}
populateDescription()
print(painArea[row])
}
var painDescription = ["very sore"]
func populateDescription() {
painDescription.removeAll()
severityText.text = ""
for cell in tableView.visibleCells {
if cell.accessoryType == .Checkmark {
painDescription.append((cell.textLabel?.text)! + " ")
}
var painArea = ""
var i = 1
while i <= painDescription.count {
painArea += painDescription[i-1] + "~"
i = i + 1
}
severityText.text = painArea
}
我希望我充分解释自己。我不希望不可见的单元格被取消选中,因此从我的文本字段中删除,除非我取消选中它。
任何想法将不胜感激。
亲切的问候
韦恩
请发表您的cellForRowAtIndexPath方法.. –
FUNC的tableView(的tableView:UITableView的,的cellForRowAtIndexPath indexPath:NSIndexPath) - > {UITableViewCell中让 细胞= tableView.dequeueReusableCellWithIdentifier(textCellIdentifier,forIndexPath:indexPath) 令行= indexPath.row 细胞.textLabel?.text = painArea [row] cell.accessoryType =。无 返回单元格 } – Wayne
在您的cellForRowAtIndexPath方法中添加if-else条件以检查单元格是否具有复选标记。如果是,那么添加accesoryType .checkmark否则.none .. –