在表格视图单元格

时间:2015-08-21 20:37:47

标签: ios swift uitableview parse-platform

我所拥有的是一个包含不同单元格的表格视图,可以与您正在聊天的其他人显示不同的消息。向左滑动单元格后,会显示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键。

1 个答案:

答案 0 :(得分:0)

试试这个:

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()
    }
 }
相关问题