重新加载UITableView后如何维护突出显示的多个UITableView行?

时间:2018-10-23 07:40:01

标签: swift uitableview

我有一个UITableView。
我可以选择多个单元格使其突出显示。
但是,每当我重新加载App时,所选状态和突出显示状态都会消失。
我想我需要在“ viewDidAppear”和“ didSelectRowAt”中放置一些代码。但是我对具体代码一无所知。
我该用什么语法?

<CKEditor
    events={{
        afterPaste: this.onChange,
        change: this.onChange,
    }}
    content= "Type something"
    config={{
        toolbarGroups: [
            { name: 'basicstyles', groups: ['basicstyles', 'cleanup'] },
            { name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi', 'paragraph'] },
            { name: 'styles', groups: ['styles'] },
            { name: 'colors', groups: ['colors'] },
        ],
    }}
/>

1 个答案:

答案 0 :(得分:0)

我建议您添加到选定的dataSource项目字段中,并在方法cellForRowAtindexPath中通过dataSource项目进行配置。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cellClass = (self.cellClass(for: indexPath) ?? self.cellClasses.first) else { return UITableViewCell() }

        let cell = tableView.dequeueReusableCell(withIdentifier: cellClass.identifier, for: indexPath)

        if let configurable = cell as? ConfigurableComponent, let object = self.object(at: indexPath) {
            let item = self.dataSource[indexPath.row]

            configurable.selected =  item.selected
        }

        return cell
    }

调用didSelectRowAt时,只需取项目并更改所选字段,然后采样即可

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      let item = self.dataSource[indexPath.row]
      item.selected = !item.selected
      tableView.reloadData()

  }