iOS如何编辑(更新)日期我表格视图单元格解析Swift
Posted
技术标签:
【中文标题】iOS如何编辑(更新)日期我表格视图单元格解析Swift【英文标题】:iOS How to edit(update) date i table view cell parse Swift 【发布时间】:2018-04-14 05:59:31 【问题描述】:我如何编辑或更新数据库使用解析的数据。 如何从我知道的单元格中删除日期,代码:
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")
)
我可以使用相同的函数来更新每个单元格的数据吗? 所以我想要这样的东西:
【问题讨论】:
【参考方案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()
)
【讨论】:
@Andrew,但正如我所见,您的问题代码有删除代码。 请问如何编辑数据,和删除日期一样的原理【参考方案2】:试试这个客户滑动:
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]
【讨论】:
以上是关于iOS如何编辑(更新)日期我表格视图单元格解析Swift的主要内容,如果未能解决你的问题,请参考以下文章
如何使用自定义按钮重新排序表格视图单元格,但不使用 ios 中的移动编辑图标