2013-10-14 7 views
5

Ich bin Parsen eine XML-Datei und die analysierten Werte in einer Tabelle view.The Tabellenansicht setzen hat nur ein section.But ich erhalte folgende Ausnahme:Assertionsfehler - [UITableView _endCellAnimationsWithContext]

2013-10 -14 15: 21: 57.250 Tabellenansicht [6068: 907] * Assertionsfehler in - [UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-2380.17/UITableView.m:909 2013-10-14 15: 22: 11.227 tableview [6068: 907] Beenden App aufgrund der nicht abgefangenen Ausnahme 'NSInternalInconsistencyException', Grund: 'Versuch, Zeile 0 in Abschnitt 0 einzufügen, aber es gibt nur 0 Zeilen in Abschnitt 0 nach dem Update' * * Erster Wurf Call-Stack: (0x33e752a3 0x3bcde97f 0x33e7515d 0x3474aab7 0x35cb0a9f 0x35de6b27 0x6a10f 0x69ce5 0x33dc6037 0x346dc599 0x6b54b 0x3478c0f5 0x33e4a683 0x33e49ee9 0x33e48cb7 0x33dbbebd 0x33dbbd49 0x379702eb 0x35cd1301 0x68bdd 0x68b64) libC++ abi.dylib: Eine Ausnahme

genannt terminate werfen

der Code ist:

/** 
The NSOperation "ParseOperation" calls addFiles: via NSNotification, on the main thread which in turn calls this method, with batches of parsed objects. The batch size is set via the kSizeOfEarthquakeBatch constant. 
*/ 
- (void)addFilesToList:(NSArray *)files { 

    NSInteger startingRow = [self.fileList count]; 
    NSLog(@"STARTING ROW:%d",startingRow); 
    NSInteger fileCount = [files count]; 
    NSLog(@"FILE COUNT : %d",fileCount); 
    NSMutableArray *indexPaths = [[NSMutableArray alloc] initWithCapacity:fileCount]; 
    NSLog(@"INDEX PATHS:%@",indexPaths); 
    for (NSInteger row = startingRow; row < (startingRow + fileCount); row++) { 
     NSLog(@"into for"); 

     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0]; 
     NSLog(@"INDEXPAth %@",indexPath); 
     [indexPaths addObject:indexPath]; 
    } 

    [self.fileList addObjectsFromArray:files]; 
    NSLog(@"ADD objects"); 
    NSLog(@"FILELIST:%@",self.fileList); 

    //GETTING EXCEPTION AT THIS LINE 

    [self.tableview insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 


#pragma mark - UITableViewDelegate\ 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

// The number of rows is equal to the number of earthquakes in the array. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return [self.fileList count]; 
    NSLog(@"NUMBER OF ROWS :%d",[self.fileList count]); 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *kFileCellID = @"Cell"; 
    myTableCell *cell = (myTableCell *)[tableView dequeueReusableCellWithIdentifier:kFileCellID]; 

    // Get the specific earthquake for this row. 
    fileList *file = (self.fileList)[indexPath.row]; 

    [cell configureWithFile:file]; 
    return cell; 
} 

Antwort

1

In meinem Fall Problem wurde ich zwei IndexPath (IndexPath, lastIndexPath) verwendet. aber für lastIndexPath.row hatte aus meinem Array bound.solve per Scheck condition.hope diese Hilfe jemand.

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, lastIndexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic]; 
+0

@Megha. Vielen Dank. –

12

Was passiert ist, dass die Tableview Sie die neue Zelle hinzugefügt werden, um die self.fileList Array getan der Veränderungen noch nicht bewusst ist. Die Reihenfolge, in der UIKit wird die neue Zelle und prüfen, ob der Abschnitt Zählung hinzuzufügen, ist leider aus Ihrer Kontrolle. Um dieses Problem jedoch zu beheben, müssen UItableview-Operationen zum Einfügen und Löschen in den Methoden reachsUpdate und endsUpdate umbrochen werden.

[self.tableView beginUpdates]; 

// Do all the insertRowAtIndexPath and all the changes to the data source array 

[self.tableView endUpdates]; 
+0

Vielen Dank - das ist für mich den Trick! – mdebeus

0

Ich aktualisierte Zeilen nach einem API-Aufruf.

Versuchen Reihen innerhalb Haupt-Thread zu aktualisieren. (Wie alle UI-Update sollte innerhalb Hauptthread erfolgen).

Try this ....

DispatchQueue.main.async { 
    self.tableView.insertRows(at: [newIndexPath], with: .bottom) 
} 
Verwandte Themen