Ios UITableView:编辑模式下单元格附件视图的外观不正确
我的iOS应用程序使用UITableViewController显示表格视图。内置的编辑按钮,用于切换到编辑模式。某些单元格需要显示附件视图,这是通过设置Ios UITableView:编辑模式下单元格附件视图的外观不正确,ios,uitableview,Ios,Uitableview,我的iOS应用程序使用UITableViewController显示表格视图。内置的编辑按钮,用于切换到编辑模式。某些单元格需要显示附件视图,这是通过设置cell.accessoryType=.detailButton完成的。同时在所有单元格上设置cell.editingAccessoryType=.none。在编辑模式下,这些单元格还显示重新排序、删除和插入附件视图 问题 问题是,当切换到编辑模式时,附件视图保留在某些单元格上,并移动到单元格的左上角。这似乎是随机发生的 以下是配置每个单元格的
cell.accessoryType=.detailButton
完成的。同时在所有单元格上设置cell.editingAccessoryType=.none
。在编辑模式下,这些单元格还显示重新排序、删除和插入附件视图
问题
问题是,当切换到编辑模式时,附件视图保留在某些单元格上,并移动到单元格的左上角。这似乎是随机发生的
以下是配置每个单元格的代码:
private func tableView(_ tableView: UITableView, cellForTextFragment fragment: Fragment, at indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: basicCellIdentifier, for: indexPath) as! BasicFragmentCell
cell.contentTextField.text = fragment.value
cell.showsReorderControl = true
switch fragment.type {
case .phoneNumber, .email:
cell.accessoryType = .detailButton
default:
cell.accessoryType = .none
}
cell.editingAccessoryType = .none
return cell
}
完整的源代码位于GitHub上:
编辑模式
非编辑模式
一种解决方法是使用标准的
UIViewController
和嵌入式UITableView
,而不是使用UITableViewController
要使编辑正常工作,当UIViewController
上的编辑状态更改时,需要在UITableView
上明确设置编辑模式,例如
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
tableView.setEditing(editing, animated: animated)
}
一种解决方法是将标准的
UIViewController
与嵌入式UITableView
一起使用,而不是使用UITableViewController
要使编辑正常工作,当UIViewController
上的编辑状态更改时,需要在UITableView
上明确设置编辑模式,例如
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
tableView.setEditing(editing, animated: animated)
}