Hi there I've been trying to create a parse connected to do list . And the part that bothers me is when I want to remove an element from a table and I want the same Object get deleted in the database . The problem is I can delete any object in the simulator but it deletes the very next object from the database instead of the one that was triggered .
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete){
LM.myList.removeAtIndex(indexPath.row)
let myQuery = PFQuery(className: "list")
myQuery.findObjectsInBackgroundWithBlock({ (Objects , error ) -> Void in
if (error != nil){
print("Error was Found")
}else if let Object = Objects {
for MyObject in Object {
if (MyObject["title"] as! String == LM.myList[indexPath.row].title && MyObject["desc"] as! String == LM.myList[indexPath.row].Description)
{
//print(LM.myList[indexPath.row ].Description)
//print(LM.myList[indexPath.row ].title)
//print(MyObject["title"] as! String)
//print(MyObject["desc"] as! String)
MyObject.deleteInBackground()
MyObject.saveInBackground()
}
}
}
}
)
tableView.deleteRowsAtIndexPaths( [indexPath] , withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
Thanks in advance :)