I am trying to delete a cell on a tableview that contains sections and this is the error I get:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.93/UITableView.m:1582
The code I am using is:
override func tableView(tableView: UITableView?, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath?) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
let cell = tableView?.cellForRowAtIndexPath(indexPath!)
let staffNic = cell?.textLabel?.text as String!
var salidaStaff:PFQuery = PFQuery(className: "StaffTrabajo")
salidaStaff.whereKeyDoesNotExist("Salida")
salidaStaff.whereKey("Nic", equalTo: staffNic)
salidaStaff.findObjectsInBackgroundWithBlock {
(objects:[AnyObject]!, error:NSError!)->Void in
if error == nil{
for object in objects{
let sweet:PFObject = object as PFObject
// Busca el id del staff
let iddd:String! = sweet.objectId as String!
// guarda los datos de salida
var query = PFQuery(className:"StaffTrabajo")
query.getObjectInBackgroundWithId(iddd) {
(gameScore: PFObject!, error: NSError!) -> Void in
if error != nil {
println(error)
} else {
gameScore["Salida"] = NSDate()
gameScore.saveInBackground()
tableView?.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: UITableViewRowAnimation.Automatic)
}
self.tableView.reloadData()
}
}
}
}
}
}
Any ideas? This is how I have my datasource setup:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return self.aventurasUnicas.count
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "\(self.aventurasUnicas.objectAtIndex(section))"
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var sectionTitle:String = aventurasUnicas.objectAtIndex(section) as String
var sectionStaff:Array = porAventura[sectionTitle]!
return sectionStaff.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell;
// Obtiene el nombre del staff y lo pone en la celda
var sectionTitle:String = aventurasUnicas.objectAtIndex(indexPath.section) as String
var sectionStaff:Array = porAventura[sectionTitle]!
let staffNic:String = sectionStaff[indexPath.row] as String
cell.textLabel?.text = staffNic
// Obtiene el subtitulo
var subtituloAventura:String = "\(sectionTitle).\(staffNic)" as String
var sectionStaff2:Array = subtituloTabla[subtituloAventura]!
let staffNic2:String = sectionStaff2[0] as String
cell.detailTextLabel?.text = staffNic2
cell.accessoryType = UITableViewCellAccessoryType.DetailButton
return cell
}