swift 中的错误当我删除一行时它会执行但崩溃
Error in swift When I delete a row it do it but crash
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
let object: PFObject = self.noteObjects.objectAtIndex(indexPath.row) as! PFObject
object.delete()
When I decided to use delete it worked but the app crashes
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
this is the error * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:1720
2016-01-19 00:07:30.451 Registro1[21154:852511] *
从 UITableView
中删除任何行后,您需要调用 reloadData()
或者您可以将该方法绑定到 beginUpdates
或 endUpdates()
.
Example:
tableView.beginUpdates()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
tableView.endUpdates()
希望对您有所帮助!
从你的代码来看,你似乎没有从数据源数组中删除相应的对象,noteObjects
。因此,调用 deleteRowsAtIndexPaths
后数据源数组计数与 TableView 内部计数不匹配
尝试在调用 tableView.deleteRowsAtIndexPaths
之前添加以下行
self.noteObjects.removeAtIndex(indexPath.row)
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
let object: PFObject = self.noteObjects.objectAtIndex(indexPath.row) as! PFObject
object.delete()
When I decided to use delete it worked but the app crashes
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
this is the error * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:1720 2016-01-19 00:07:30.451 Registro1[21154:852511] *
从 UITableView
中删除任何行后,您需要调用 reloadData()
或者您可以将该方法绑定到 beginUpdates
或 endUpdates()
.
Example:
tableView.beginUpdates()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
tableView.endUpdates()
希望对您有所帮助!
从你的代码来看,你似乎没有从数据源数组中删除相应的对象,noteObjects
。因此,调用 deleteRowsAtIndexPaths
尝试在调用 tableView.deleteRowsAtIndexPaths
self.noteObjects.removeAtIndex(indexPath.row)