每当我单击编辑按钮时,如何在右侧创建用于编辑内容的信息按钮以及删除控件(左侧)?
(类似这样)
`
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
objects.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}`
最佳答案
使用附件类型。
在cellForRowAt方法中,添加
cell.editingAccessoryType = .detailButton
并通过以下方式对其采取行动
override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
print("Accessory btn tapped")
}
关于ios - 如何在 UITableViewCell 中创建信息按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49962898/