iOS如何编辑(更新)日期我表视图单元解析Swift

时间:2018-04-14 05:59:32

标签: ios swift uitableview parse-platform

我如何编辑或更新数据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")
                                }
                            }
                        })
                    } 
}

我可以使用相同的功能更新每个单元格的数据吗? 所以我想要这样的东西: enter image description here

2 个答案:

答案 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]
}