@@ -481,14 +481,14 @@ - (void) toggleDropDown {
481
481
[VPPDropDown addNumberOfRows: rowsToAdd forSection: self .indexPath.section inTableView: self .tableView];
482
482
[self updateGlobalIndexPaths ];
483
483
484
- NSMutableArray *indexPaths = [NSMutableArray array ];
485
- for (int i = 1 ; i <= [_elements count ]; i++) {
486
- NSIndexPath *ip = [NSIndexPath indexPathForRow: _rootIndexPath.row+i inSection: _rootIndexPath.section];
487
- [indexPaths addObject: ip];
488
- }
489
-
490
484
if (self.usesEntireSection ) {
491
485
// we can add or remove the cells as we manage the entire section
486
+ NSMutableArray *indexPaths = [NSMutableArray array ];
487
+ for (int i = 1 ; i <= [_elements count ]; i++) {
488
+ NSIndexPath *ip = [NSIndexPath indexPathForRow: _rootIndexPath.row+i inSection: _rootIndexPath.section];
489
+ [indexPaths addObject: ip];
490
+ }
491
+
492
492
if (_expanded) {
493
493
// table view insert rows
494
494
[_tableView insertRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationFade];
@@ -507,6 +507,17 @@ - (void) toggleDropDown {
507
507
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: _rootIndexPath.section];
508
508
[_tableView reloadSections: indexSet withRowAnimation: UITableViewRowAnimationFade];
509
509
}
510
+
511
+ if (_expanded) {
512
+ // scroll to last cell if needed
513
+ NSIndexPath *lastRow = [NSIndexPath indexPathForRow: _globalRootIndexPath.row+[_elements count ] inSection: _globalRootIndexPath.section];
514
+ UITableViewCell *lastVisibleCell = [self .tableView.visibleCells lastObject ];
515
+ NSIndexPath *lastVisibleIndexPath = [self .tableView indexPathForCell: lastVisibleCell];
516
+ // lets scroll if only half of the cells are visible
517
+ if (lastVisibleIndexPath.section <= lastRow.section && lastVisibleIndexPath.row < lastRow.row ) {
518
+ [self .tableView scrollToRowAtIndexPath: lastRow atScrollPosition: UITableViewScrollPositionBottom animated: YES ];
519
+ }
520
+ }
510
521
}
511
522
512
523
0 commit comments