代码之家  ›  专栏  ›  技术社区  ›  Vyachaslav Gerchicov

是否在Swift的UITableView中保留单元格?

  •  0
  • Vyachaslav Gerchicov  · 技术社区  · 7 年前

    UITableView 默认情况下,重用单元格。但在我的例子中,有些细胞有 UITextField

    我当前使用的代码示例:

    override func viewDidLoad() {
            super.viewDidLoad()
            tableView.register(UINib(nibName: "TPAddressInfoTableViewCell", bundle: nil), forCellReuseIdentifier: InfoCellIdentifier)
            ...
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let item = items[indexPath.row]
            switch item.appearance {
            case .textWithTitle:
                let cell = tableView.dequeueReusableCell(withIdentifier: InfoCellIdentifier) as! TPAddressInfoTableViewCell
                return cell
            case .picker:
                ...
    

    UITextFieldDelegate 每个电池的电流 UIViewController

    1 回复  |  直到 7 年前
        1
  •  4
  •   vadian    7 年前

    不要保留细胞

    在数据模型中保存单元格的UI元素的所有值,并在中恢复这些值 cellForRow

    例如,将相应的模型项传递给中的单元格 并在属性更改时将文本字段字符串保存在属性中。