【问题标题】:Deleting a key in Parse upon clicking "Delete" in table view cell在表格视图单元格中单击“删除”时删除 Parse 中的键
【发布时间】:2015-08-21 20:37:46
【问题描述】:

我拥有的是一个带有不同单元格的表格视图,这些单元格显示与您正在聊天的其他人的不同消息。在向左滑动单元格时,会出现一个Delete 选项。我希望能够在 Parse 中删除单元格本身以及与之关联的Room。这是我目前所拥有的:

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()
    }
}

此函数显示Delete 选项,当我单击它时,我希望它删除单击它的单元格。有谁知道查询中的内容?我有一个Message 类,我想删除与我删除的单元格关联的Room 键。

【问题讨论】:

  • 该消息是 indexPath 中唯一的消息吗?如果是这样,您可以使用 ObjectId 找到ObjectInBackground。现在,您将结果限制为仅返回与房间名称相同的房间。如果您不想删除整个房间及其消息,而只想删除该房间中的特定消息,则必须如上所述缩小范围

标签: ios swift uitableview parse-platform


【解决方案1】:

试试这个:

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()
    }
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多