我有一个UITableViewCell被选中,但是当我调用这段代码时:
self.tableView.beginUpdates()
self.tableView.reloadSections(IndexSet(integer: 0), with: .none)
self.tableView.endUpdates()
它失去了选择状态,但即使我做了这两件事:
self.tableView.beginUpdates()
self.tableView.reloadSections(IndexSet(integer: 0), with: .none)
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: false, scrollPosition: .none)
self.tableView.endUpdates()
和
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// get cell
cell.setSelected(true, animated: false)
细胞失去其选择状态一秒钟,这是不好的。我希望单元格的外观即使眨眼也不会改变。
注意:我将日志语句放在通常的shouldHighlight和didUnSelect等方法中,但没有受到那些人的打击。
不要在beginUpdates()
和endUpdates()
中包含代码行。这开始了一个“动画事务”来动画tableView
操作在一起。我假设在这种情况下tableView
运行动画,即使你将.none
设置为动画,从而以毛刺结束。