iOS 如何编辑(更新)日期 i table 查看单元格解析 Swift
iOS How to edit(update) date i table view cell parse Swift
我如何使用解析来编辑或更新数据库中的数据。
如何从我知道的单元格中删除日期,代码:
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")
}
}
})
}
}
我可以使用相同的函数来更新每个单元格的数据吗?
所以我想要这样的东西:
试试这个。
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()
})
}
}
试试这个客户刷卡:
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]
}
我如何使用解析来编辑或更新数据库中的数据。 如何从我知道的单元格中删除日期,代码:
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")
}
}
})
}
}
我可以使用相同的函数来更新每个单元格的数据吗?
所以我想要这样的东西:
试试这个。
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()
})
}
}
试试这个客户刷卡:
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]
}