mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-01 12:23:20 +08:00
Merge pull request #676 from steveram/index-path-for-node
Add a indexPathForNode: to ASTableView
This commit is contained in:
@@ -227,6 +227,15 @@
|
||||
*/
|
||||
- (ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath;
|
||||
|
||||
/**
|
||||
* Similar to -indexPathForCell:.
|
||||
*
|
||||
* @param cellNode a cellNode part of the table view
|
||||
*
|
||||
* @returns an indexPath for this cellNode
|
||||
*/
|
||||
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode;
|
||||
|
||||
/**
|
||||
* Similar to -visibleCells.
|
||||
*
|
||||
|
||||
@@ -345,6 +345,11 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
|
||||
return [_dataController nodeAtIndexPath:indexPath];
|
||||
}
|
||||
|
||||
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode
|
||||
{
|
||||
return [_dataController indexPathForNode:cellNode];
|
||||
}
|
||||
|
||||
- (NSArray *)visibleNodes
|
||||
{
|
||||
NSArray *indexPaths = [self indexPathsForVisibleRows];
|
||||
|
||||
@@ -173,6 +173,8 @@ typedef NSUInteger ASDataControllerAnimationOptions;
|
||||
|
||||
- (ASCellNode *)nodeAtIndexPath:(NSIndexPath *)indexPath;
|
||||
|
||||
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode;
|
||||
|
||||
- (NSArray *)nodesAtIndexPaths:(NSArray *)indexPaths;
|
||||
|
||||
- (NSArray *)completedNodes; // This provides efficient access to the entire _completedNodes multidimensional array.
|
||||
|
||||
@@ -632,6 +632,22 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
return _completedNodes[indexPath.section][indexPath.row];
|
||||
}
|
||||
|
||||
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode;
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
|
||||
// Loop through each section to look for the cellNode
|
||||
for (NSUInteger i = 0; i < [_completedNodes count]; i++) {
|
||||
NSArray *sectionNodes = _completedNodes[i];
|
||||
NSUInteger cellIndex = [sectionNodes indexOfObjectIdenticalTo:cellNode];
|
||||
if (cellIndex != NSNotFound) {
|
||||
return [NSIndexPath indexPathForRow:cellIndex inSection:i];
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *)nodesAtIndexPaths:(NSArray *)indexPaths
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
|
||||
@@ -428,4 +428,27 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testIndexPathForNode
|
||||
{
|
||||
CGSize tableViewSize = CGSizeMake(100, 500);
|
||||
ASTestTableView *tableView = [[ASTestTableView alloc] initWithFrame:CGRectMake(0, 0, tableViewSize.width, tableViewSize.height)
|
||||
style:UITableViewStylePlain
|
||||
asyncDataFetching:YES];
|
||||
ASTableViewFilledDataSource *dataSource = [ASTableViewFilledDataSource new];
|
||||
|
||||
tableView.asyncDelegate = dataSource;
|
||||
tableView.asyncDataSource = dataSource;
|
||||
|
||||
[tableView reloadDataWithCompletion:^{
|
||||
for (NSUInteger i = 0; i < NumberOfSections; i++) {
|
||||
for (NSUInteger j = 0; j < NumberOfRowsPerSection; j++) {
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
|
||||
ASCellNode *cellNode = [tableView nodeForRowAtIndexPath:indexPath];
|
||||
NSIndexPath *reportedIndexPath = [tableView indexPathForNode:cellNode];
|
||||
XCTAssertEqual(indexPath.row, reportedIndexPath.row);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user