だから私はUITableView
ビデオライブラリを表す を持っています。ライブラリのデータソースは、各キーNSMutableDictionary
の for を含むです。NSMutableArray
各配列には、各値のすべての情報を含む配列が含まれています。
NSMutableDictionary
-> を含む Foreach Key a NSMutableArray
-> NSMutableArrays
.
tableSectionData
私のデータソースです。
最初のセクションに行を挿入し、別のセクションの別の行を削除しようとしています。これは私が使用しているコードです:
EDITこれは新しい試みです。最初にデータソースを更新してから、データソースでインデックス付けされた対応する行を追加および削除します。
[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];
行を挿入したい場合は最初に行を削除する必要があるため、これはうまくいくと思いました(両方を行いたい場合)。
具体的なエラーは次のとおりです。
'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).'
エラーの内容はわかっていますが、セクションに対応する行数がありませんが、コードに間違いがなく、データソースをログに記録したところ、目的の結果に対応しています。
どんな助けや提案も大歓迎です!