My iOS app uses a UITableViewController to show a table view. The built-in edit button to switch to edit mode. Some of the cells need to show an accessory view, which is done by setting cell.accessoryType = .detailButton
. At the same time cell.editingAccessoryType = .none
is set on all the cells. The cells also show reordering, delete, and insert accessory views while in edit mode.
Problem
The problem is that when switching to edit mode, the accessory view stays behind on some cells, and moves to the top left corner of the cell. This seems to happen at random.
Below is the code which configures each cell:
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
}
The full source is on GitHub: https://github.com/lukevanin/OCRAI
Edit mode
Non-edit mode
A workaround is to use a standard UIViewController
with an embedded UITableView
, instead of using a UITableViewController
.
For editing to work correctly, the editing mode needs to be set explicitly on the UITableView
when the editing state changes on the UIViewController
, eg
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
tableView.setEditing(editing, animated: animated)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.