Quindi ho uno UITableView
che rappresenta una libreria video. L'origine dati della libreria è NSMutableDictionary
che contiene uno NSMutableArray
per ciascuna delle sue chiavi. Ciascuno degli array contiene una matrice con tutte le informazioni per ciascun valore.Inserimento di righe ed eliminazione di righe contemporaneamente. UITableView
NSMutableDictionary
-> Foreach Key a NSMutableArray
che contiene ->NSMutableArrays
.
tableSectionData
è la mia origine dati.
Ho cercato di inserire una riga nella prima sezione ed eliminare un'altra riga in un'altra sezione. Questo è il codice che sto usando:
EDIT Questo è il nuovo tentativo. Per prima cosa aggiorno l'origine dati e poi aggiungo ed elimina le righe corrispondenti che sono indicizzate con my dataSource.
[mainTableView beginUpdates];
NSMutableDictionary *clone = [[NSMutableDictionary alloc]
initWithDictionary:self.tableSectionData copyItems:YES];
for (NSString *key in [clone allKeys]) {
if([key isEqualToString:@"Videos available for download"]) {
for (NSArray *videoArray in [clone objectForKey:key]) {
if ([[videoArray objectAtIndex:0] isEqualToString:helper.videoName]) {
[[self.tableSectionData objectForKey:@"Downloaded videos"]
addObject:videoArray];
NSUInteger insertIndex = [[self.tableSectionData
objectForKey:@"Downloaded videos"]
indexOfObject:videoArray];
NSIndexPath *pathToInsert = [NSIndexPath
indexPathForRow:insertIndex inSection:0];
NSArray *indexesToAddition = [NSArray
arrayWithObject:pathToInsert];
[mainTableView insertRowsAtIndexPaths:indexesToAddition
withRowAnimation:UITableViewRowAnimationFade];
[[self.tableSectionData
objectForKey:@"Videos available for download"] removeObject:videoArray];
NSUInteger deleteIndex = [[self.tableSectionData
objectForKey:@"Videos available for download"] indexOfObject:videoArray];
NSIndexPath *pathToDelete = [NSIndexPath
indexPathForRow:deleteIndex inSection:1];
NSArray *indexesToDeletion = [NSArray arrayWithObject:
pathToDelete];
[mainTableView deleteRowsAtIndexPaths:indexesToDeletion
withRowAnimation:UITableViewRowAnimationFade];
}
}
}
}
[mainTableView endUpdates];
Ho pensato che questo avrebbe funzionato dal momento che ho per eliminare prima fila se voglio inserire uno (nel caso che voglio fare entrambe le cose.)
L'errore specifico è il seguente:
'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
So cosa dice l'errore, che non ho un numero corrispondente di righe sulla sezione, ma non vedo il mio errore sul codice e ho registrato l'origine dati e corrisponde al risultato desiderato.
Qualsiasi aiuto e suggerimento sarebbe molto apprezzato!
Ho già provato questo, ma non ha funzionato. Attaccherò agli aggiornamenti di inizio e fine! – Joze