从tableView中删除单元格时,动画运行良好,但tableView数据不会重新加载。我试着在没有.beginUpdates()和.endUpdates()的情况下运行,而是使用.reloadData(),这个过程可以工作,但是动画不能工作。
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
switch editingStyle {
case .Delete:
// remove the deleted item from the model
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
context.deleteObject(coreData[indexPath.row] as NSManagedObject)
coreData.removeAtIndex(indexPath.row)
do {
try context.save()
} catch {
print("Error deleting NSManagedObject")
}
tableView.beginUpdates()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
tasks.removeAtIndex(indexPath.row)
names.removeAtIndex(indexPath.row)
ids.removeAtIndex(indexPath.row)
tableView.endUpdates()
// remove the deleted item from the `UITableView`
default:
return
}
}顺便说一下,tasks数组是tableView的主要数据。
如何在删除单元格时重新加载数据,并使用平滑的删除动画?
发布于 2015-12-22 04:20:27
有两件事需要考虑:
begin/endUpdates,因为您只进行一次调用来更新表视图。https://stackoverflow.com/questions/34408215
复制相似问题