【问题标题】:UITableView: Incorrect appearance of cell accessory view in edit modeUITableView:编辑模式下单元格附件视图的外观不正确
【发布时间】:2017-03-02 14:55:44
【问题描述】:

我的 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 上:https://github.com/lukevanin/OCRAI

编辑模式

非编辑模式

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    一种解决方法是使用标准的UIViewController 和嵌入的UITableView,而不是使用UITableViewController

    为使编辑正常工作,当UIViewController 上的编辑状态发生变化时,需要在UITableView 上显式设置编辑模式,例如

    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
        tableView.setEditing(editing, animated: animated)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多