Mam pewne problemy z usunięciem wiersz z mojego Tableview w Swift, iOS 8, Xcode 6 Beta 6. Za każdym razem staram się usunąć wiersz pojawia się błąd wzdłuż liniisystemów iOS 8 Swift: deleteRowsAtIndexPaths wywala
awariaAssertion w - [UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3302.3.1/UITableView.m:1581 30.08.2014 20: 31: 00,971 Klasa katalog [13290: 3241692] ** * Kończenie aplikacji ze względu na nieprzechwycony wyjątek "NSInternalInconsistencyException", przyczyna: "Nieprawidłowa aktualizacja: niepoprawna liczba wierszy w sekcji 1. Liczba wierszy zawartych w istniejącym se ction po aktualizacji (25) musi być równy liczbie wierszy zawartych w tej sekcji przed aktualizacją (25), plus lub minus liczba wierszy wstawionych lub usuniętych z tej sekcji (0 wstawionych, 1 usuniętych) i plus lub minus liczba wierszy przeniesionych do lub z tej sekcji (0 wprowadzono, 0 przesunięto).
Przeczytałem wszystkie odpowiedzi na ten częsty problem tutaj i czuję, że spełniłem zalecane warunki. Pozycja wydaje się być do usunięcia z modelu danych - kiedy przeładowuję aplikację, usunięty element zniknął z tabeli - ale wydaje się, że w odpowiednim pliku sqlite są pewne pozostałości i oczywiście matematyka nie działa t sumują się. W println, który wypluwa indexPath, pokazuje poprawną sekcję i wiersz. Jestem bardzo zaintrygowany. To powinno być proste, ale brakuje mi czegoś głupiego, jestem pewien, podejrzewam, że w procesie usuwania danych. Pełny projekt na Github.
func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
return fetchedResultController.sections.count
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return fetchedResultController.sections[section].numberOfObjects
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableViewMain.dequeueReusableCellWithIdentifier("CellMain", forIndexPath: indexPath) as UITableViewCell
let personForRow = fetchedResultController.objectAtIndexPath(indexPath) as Person
cell.textLabel.text = personForRow.fullName()
return cell
}
func tableView(tableView: UITableView!, canEditRowAtIndexPath indexPath: NSIndexPath!) -> Bool {
return true
}
func tableView(tableView: UITableView!, editingStyleForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.Delete
}
func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) {
println("section and row \(indexPath.section) \(indexPath.row) ")
if (editingStyle == UITableViewCellEditingStyle.Delete) {
let personForRow : NSManagedObject = fetchedResultController.objectAtIndexPath(indexPath) as Person
context?.deleteObject(personForRow)
context?.save(nil)
tableViewMain.beginUpdates()
tableViewMain.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
tableViewMain.endUpdates()
}
możliwy duplikat [crash na deleteRowsAtIndexPaths] (http://stackoverflow.com/questions/4186251/crash-on-deleterowsatindexpaths) – durron597
Nie duplikat. Odpowiedzi na te pytania były niewystarczające. –