【发布时间】:2015-09-08 03:21:44
【问题描述】:
我正在制作一个应用程序,该应用程序当前将解析对象保存到本地数据存储区和 parse.com。然后我运行一个查询,将每个对象保存到一个数组中,以便我可以在表格视图中显示它。由于我过去发布的问题here 和here,到目前为止一切正常。
所以现在信息正按我希望的那样正确显示。但现在,我也希望能够删除条目。我想滑动表格,当点击删除时,对象会从本地数据存储中取消固定,并且相同的项目也会从云中删除。
这是我目前的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// var lighthouse = self.lighthouses[indexPath.row]
var data = self.arrayToPopulateCells[indexPath.row]
let cell = tableView.dequeueReusableCellWithIdentifier("locationCell") as! lighthouseCell
let row = indexPath.row
cell.cellName.text = data.name
cell.cellPlace.text = data.locality
cell.cellDate.text = "\(data.date)"
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.selectedLighthouse = self.arrayToPopulateCells[indexPath.row]
self.performSegueWithIdentifier("lighthouseDetailViewSegue", sender: self)
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
self.arrayToPopulateCells.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
“arrayToPopulateCells”是在我的查询期间存储解析对象的位置。
显然我能够删除 indexpath.row 中的单元格,但是我如何获取该单元格中的信息,并找到匹配的解析对象以取消固定和删除?
【问题讨论】:
-
你能告诉我你在 CellForRowAtINDex TableView Delegate 中写了什么
标签: ios swift uitableview parse-platform