セルのaccessoryType
にチェックマークを付けるtableViewCellがあります。私は、セルの内容を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) LET行= indexPath.row セル.textLabel?.text = painArea [行] cell.accessoryType = .None 戻りセル } – Wayne
セルをチェックするためのcellForRowAtIndexPathメソッドのif-else条件にチェックマークが付いているかどうかを指定します。 Yesの場合は、accesoryType .checkmarkを追加します。それ以外の場合は.none .. –