如何实现“滑动删除”呢?
同样是在tableView里面操作这些代码:
// Override to support conditional editing of the table view.左滑删除
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
// Override to support editing the table view.左滑删除
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
print("delete table view cell")
if editingStyle == .Delete {
//获取数组中要删除的数据
let this_password = self.todos[indexPath.row]
this_password.delete { (result) in
if(result.isSuccess){
// 根据 result.isSuccess 可以判断是否删除成功
self.todos.removeAtIndex(indexPath.row)
//删除对应的cell
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else {
if (result.error != nil){
print(result.error?.reason)
// 如果删除失败,可以查看是否当前正确使用了 ACL
}
}
}
}
你可以看到,我们成功的删除掉了第一条数据: