简体   繁体   English

在表格视图单元格中单击“删除”后,在“解析”中删除键

[英]Deleting a key in Parse upon clicking “Delete” in table view cell

What I have is a table view with different cells that display different messages with other people you're chatting with. 我所拥有的是一个具有不同单元格的表格视图,这些单元格与您正在聊天的其他人显示不同的消息。 Upon swiping the cell to the left, a Delete option shows up. 将单元格向左滑动时,将显示“ Delete选项。 I want to be able to delete both the cell itself as well as the Room associated with it in Parse. 我希望能够删除单元格本身以及在Parse中与其关联的Room This is what I have so far: 这是我到目前为止的内容:

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == UITableViewCellEditingStyle.Delete {
        //Delete messages here
        let query = PFQuery(className: "Message")
        query.whereKey("Room", equalTo: ??????)

        tableView.beginUpdates()
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
        tableView.endUpdates()
    }
}

This function displays the Delete option, and when I click it, I want it to delete the cell it was clicked in. Does anyone know what goes inside the query? 此函数显示“ Delete选项,当我单击它时,我希望它删除单击它的单元格。有人知道查询中包含什么吗? I have a Message class and I want to delete the Room key that's associated with the cell I delete. 我有一个Message类,我想删除与删除的单元格关联的Room键。

Try this : 尝试这个 :

var dataToDelete:NSMutableArray = []  // this is a dummy array just to replicate your array 
 func tableView(tableView: UITableView, commitEditingStyle editingStyle:   UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
    var object  = dataToDelete[indexPath.row] as! PFObject
    tableView.beginUpdates()
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
    tableView.endUpdates()
      object.delete()
    }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM