Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView:编辑模式下单元格附件视图的外观不正确_Ios_Uitableview - Fatal编程技术网

Ios UITableView:编辑模式下单元格附件视图的外观不正确

Ios UITableView:编辑模式下单元格附件视图的外观不正确,ios,uitableview,Ios,Uitableview,我的iOS应用程序使用UITableViewController显示表格视图。内置的编辑按钮,用于切换到编辑模式。某些单元格需要显示附件视图,这是通过设置cell.accessoryType=.detailButton完成的。同时在所有单元格上设置cell.editingAccessoryType=.none。在编辑模式下,这些单元格还显示重新排序、删除和插入附件视图 问题 问题是,当切换到编辑模式时,附件视图保留在某些单元格上,并移动到单元格的左上角。这似乎是随机发生的 以下是配置每个单元格的

我的iOS应用程序使用UITableViewController显示表格视图。内置的编辑按钮,用于切换到编辑模式。某些单元格需要显示附件视图,这是通过设置
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)
}