Merge pull request #168 from facebook/editing

Fix crash while deleting in multiple sections
This commit is contained in:
Nadine Salter
2014-12-17 13:34:47 -08:00
2 changed files with 4 additions and 12 deletions

View File

@@ -339,10 +339,8 @@ static void *kASDataUpdatingQueueContext = &kASDataUpdatingQueueContext;
}
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths {
// sort indexPath in revse order to avoid messing up the index when deleting
NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath *obj1, NSIndexPath *obj2) {
return [obj2 compare:obj1];
}];
// sort indexPath in order to avoid messing up the index when deleting
NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingSelector:@selector(compare:)];
dispatch_async([ASDataController sizingQueue], ^{
[self asyncUpdateDataWithBlock:^{
@@ -402,13 +400,7 @@ static void *kASDataUpdatingQueueContext = &kASDataUpdatingQueueContext;
[self syncUpdateDataWithBlock:^{
NSArray *indexPaths = ASIndexPathsForMultidimensionalArray(_nodes);
// sort indexPath in reverse order to avoid messing up the index when inserting in several batches
NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath *obj1, NSIndexPath *obj2) {
return [obj2 compare:obj1];
}];
DELETE_NODES(_nodes, sortedIndexPaths);
DELETE_NODES(_nodes, indexPaths);
NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc] initWithIndexesInRange:NSMakeRange(0, _nodes.count)];
DELETE_SECTIONS(_nodes, indexSet);

View File

@@ -47,7 +47,7 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3;
}
- (void)deleteNodesAtIndexPaths:(NSArray *)indexPaths {
[indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
[indexPaths enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
std::vector<CGSize> &v = _nodeSizes[indexPath.section];
v.erase(v.begin() + indexPath.row);
}];