【发布时间】:2019-05-18 11:30:05
【问题描述】:
晚安,女士们,先生们, 我目前正在习惯 Swift,并想从一个小 todo 应用程序开始。到目前为止,我可以添加一个项目并在上下文中持久地保护它。添加项目后,它将显示在表格视图中。现在,我想使用检查滑动来删除已添加的项目,并在我的上下文中保护这些信息。使用滑动删除非常好。
有人知道如何实现这一点吗?我试图自己解决它,但无法完成。之前在这里问过类似的问题,但没有得到正确的答案:Add strikethrough to tableview row with a swipe
func checkAccessoryType(cell: UITableViewCell, isCompleted: Bool) {
if isCompleted {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let todo = CoreDataManager.shared.getTodoItem(index: indexPath.row)
todo.completed = !todo.completed
CoreDataManager.shared.safeContext()
if let cell = tableView.cellForRow(at: indexPath){
checkAccessoryType(cell: cell, isCompleted: todo.completed)
}
}
【问题讨论】:
标签: ios swift uitableview tableview strikethrough