Skip to content

Commit 786fa8b

Browse files
author
Michael Lupo
committed
Fix Table View scrolling for mulitple sections
The TableViewTests exposed an inadequacy in the algorithm that searched for cells that are off the screen. This commit addresses that by scrolling to the last visible row then scrolling the section by CGRect. Both are needed to make this hack work.
1 parent 21178f9 commit 786fa8b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Additions/UIView-KIFAdditions.m

+10-2
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,20 @@ - (UIAccessibilityElement *)accessibilityElementMatchingBlock:(BOOL(^)(UIAccessi
264264
break;
265265
}
266266

267-
// Skip visible rows because they are already handled
267+
// Skip visible rows because they are already handled.
268268
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
269269
if ([indexPathsForVisibleRows containsObject:indexPath]) {
270-
continue;
270+
@autoreleasepool {
271+
//scroll to the last row of each section before continuing. Attemps to ensure we can get to sections that are off screen. KIF tests (e.g. testButtonAbsentAfterRemoveFromSuperview) fails without this line. Also without this... we can't expose the next section (in code downstream)
272+
[tableView scrollToRowAtIndexPath:[indexPathsForVisibleRows lastObject] atScrollPosition:UITableViewScrollPositionNone animated:animationEnabled];
273+
continue;
274+
}
271275
}
272276

277+
//expose the next section
278+
CGRect sectionRect = [tableView rectForSection:section];
279+
[tableView scrollRectToVisible:sectionRect animated:NO];
280+
273281
@autoreleasepool {
274282
// Scroll to the cell and wait for the animation to complete. Using animations here may not be optimal.
275283
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:animationEnabled];

0 commit comments

Comments
 (0)