[英]Deleting an object in a tableView cell from Parse
I am attempting to delete certain objects from Parse. 我试图从Parse中删除某些对象。 The user will be able to save posts and I am trying to implement a way for them to delete them.
用户将能够保存帖子,我正在尝试实现一种方法来删除它们。 The saved posts can be found in a TableView.
保存的帖子可以在TableView中找到。
I currently have the following. 我目前有以下内容。
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .Default, title: "Remove") { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
let query = PFQuery(className: "SavedObjects")
query.orderByDescending("createdAt")
query.whereKey("savedByUser", equalTo: (PFUser.currentUser()?.username)!)
query.findObjectsInBackgroundWithBlock({ (objects : [PFObject]?, error: NSError?) -> Void in
if error == nil {
for object in objects! {
object.deleteInBackground()
}
}
})
self.tableView.reloadData()
}
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction]
}
The object.deleteInBackground()
does work, but it deletes all objects that were saved by the user. object.deleteInBackground()
确实有效,但它删除了用户保存的所有对象。 I would like it to only delete the object that the cell represents. 我希望它只删除单元格所代表的对象。
I have also tried to use object.deleteInBackgroundWithTarget([indexPath.row], selector: nil)
but have had no luck. 我也试过使用
object.deleteInBackgroundWithTarget([indexPath.row], selector: nil)
但是没有运气。
if I understood your question correctly, I think you need to add another query.WhereKey()
filtering by the objectId of the corresponding row saved on Parse. 如果我正确理解你的问题,我认为你需要添加另一个
query.WhereKey()
过滤Parse上保存的相应行的objectId。 This way the call to object.deleteInBackground()
will only delete the cell you selected from the TableView. 这样对
object.deleteInBackground()
的调用只会删除从TableView中选择的单元格。 I hope this was helpful! 我希望这可以帮到你!
Valerio 瓦莱里奥
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.