をスクロールしたときに、私はインクリメント整数変数に新しい行を挿入バーボタンアイテムを持って変更します。カスタムUITableViewCellのは
class TableViewController: UITableViewController {
var personNo = 0
var data = [String]()
@IBAction func addPerson(_ sender: UIBarButtonItem) {
personNo += 1
tableView.beginUpdates()
data.append("Person \(personNo)")
tableView.insertRows(at: [IndexPath(row: data.count - 1, section: 0)], with: .automatic)
tableView.endUpdates()
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "newPerson") as! CustomCell
cell.lblPerson?.text = "Person \(personNo): "
// Configure the cell...
return cell
}
}
を行を追加するセルの値の変更は時にテーブルビューを動作しますが、スクロールさ:
なぜこの出来事はあるとどのように私は、EAの状態を保存することができますCHセル?あなたの目的のために、私はお勧め:あなたは
cell.lblPerson?.text = data[indexPath.row]
余談で
cell.lblPerson?.text = "Person \(personNo): "
を交換して、データ・ソース・アレイ(data
)
からデータを取得する必要があります
使用データ配列:
あなたは
indexPath.row
値を使用することができます。それはなぜあなたが各セルで同じ価値を得るかということです。 – Pawan