iOS Swift 3从TableView删除一行使用解析
问题描述:
我正在构建一个iOS应用程序,我试图从UITableView中删除一行。我也使用Parse作为应用的移动后端。下面是删除方法的代码:iOS Swift 3从TableView删除一行使用解析
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: "Receipts")
let currReceipt = receipts[indexPath.row]
query.whereKey("objectId", equalTo: currReceipt.objectId!)
query.findObjectsInBackground(block: { (objects, error) in
if error != nil {
self.createAlert(title: "Oops! Something went wrong number 1!", message: "We could not delete the receipt")
print("THERE WAS AN ERROR DELETING THE OBJECT")
}else{
for object in objects!{
self.receipts.remove(at: indexPath.row)
object.deleteInBackground()
self.table.reloadData()
}
}
})
}
}
只是为了澄清,只会有一个收据与任何给定的“OBJECTID”的数据库,所以query.findObjectsInBackground应该只返回一个对象。
当我尝试在模拟器中删除一行时,即使我看到对象存在于数据库中,我也会收到错误“找不到对象”。我究竟做错了什么?
UPDATE 很长时间后找到我的解决方案。对于任何感兴趣的人来说,它必须使用读写权限的默认ACL值。这里是链接到答案:Parse weird bug in Swift that causes ACL write permissions to change to an objectId
答
这可能是一个错字,但为什么你有!在这一行?
query.whereKey("objectId", equalTo: currReceipt.objectId!)
当没有“!”时,我得到的警告是“表达式[是]从'字符串'隐式强制?任何“ –
找到我的解决方案,经过几天的搜索...如果你有兴趣:http://*.com/questions/34926827/parse-weird-bug-in-swift-that-causes-acl-write -permissions到变化到一个-objec –