ios - 单击 TableView 单元格中的 "Delete"后删除 Parse 中的键

标签 ios swift uitableview parse-platform

我拥有的是一个包含不同单元格的表格 View ,这些单元格显示与您正在聊天的其他人的不同消息。向左滑动单元格后,会出现一个删除选项。我希望能够在 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()
    }
}

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

最佳答案

试试这个:

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

关于ios - 单击 TableView 单元格中的 "Delete"后删除 Parse 中的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32148895/

相关文章:

iphone - UIPickerView 在运行时更改所选项目

ios - Swift,谷歌地图适用于所有标记

ios - 为什么这个 swiftui View 不更新?

ios - Xcode 7 中的脂肪库

ios - TableView _ :didSelectRowAt: is triggered only on slide touch

ios - 当第一个触发popToRootViewController时检测标签栏项目上的第二次点击

ios - "No Results"当没有人脸出现时(Swift)-简单

iphone - 单击 UIButton 时从一个 UIViewController 重定向到另一个 UIViewController

ios - UITableView具有白色背景而不是清晰的背景

ios - 带有 UISearchBar 的奇怪行为 UIRefreshControl