即時製作一個當前將解析對象保存到本地數據存儲區和parse.com的應用程序。然後我運行一個查詢,將每個對象保存到一個數組中,以便我可以在一個表視圖中顯示它。到目前爲止,一切都很好,謝謝我過去發佈的問題here和here。parse.com swift - 取消固定和刪除tableView單元格中的對象
所以現在信息顯示正確,因爲我希望。但現在,我希望能夠刪除條目。我想滑動表格,並在點擊刪除時,該對象從本地數據存儲中取消固定,並且該相同的項目也從雲中移除。
這裏是我當前的代碼如下:
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中代表寫的是什麼 – Kavita