我拥有的是一个包含不同单元格的表格 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/