我如何编辑或更新数据i数据库使用解析。 如何从我知道的单元格中删除日期,代码:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
let query = PFQuery(className: "requests")
let currReceipt = self.data[indexPath.row]
query.whereKey("objectId", equalTo: currReceipt.objectId!)
query.findObjectsInBackground(block: { (objects, error) in
if error != nil {
self.alert(message: "We could not delete the receipt", title: "Oops! Something went wrong number 1!")
}else{
for object in objects!{
self.data.remove(at: indexPath.row)
object.deleteInBackground()
self.tableView.reloadData()
self.alert(message: "Successfully delete from open task list", title: "Task done")
}
}
})
}
}
答案 0 :(得分:1)
试试这个。
let query = PFQuery(className: "requests")
let currReceipt = self.data[indexPath.row]
query.whereKey("objectId", equalTo: currReceipt.objectId!)
query.findObjectsInBackground(block: { (objects, error) in
if error != nil {
self.alert(message: "We could not delete the receipt", title: "Oops! Something went wrong number 1!")
}
else {
//UPDATE OBJECT
object["agestart"] = self.fromAge.text
object["ageend"] = self.toAge.text
object["location"] = self.location.text
object.saveInBackground(block: { (success, error) in
if error != nil {
self.alert(message: "Error while updating object", title: "Oops! Something went wrong number 1!")
}
else {
self.tableView.reloadData()
})
}
}
答案 1 :(得分:1)
尝试此客户滑动:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
// delete item at indexPath
}
let update = UITableViewRowAction(style: .normal, title: "Update") { (action, indexPath) in
// update item at indexPath
}
update.backgroundColor = UIColor.grey
return [delete, update]
}