Reputation: 650
I've just implemented the AGPhotoBrowser
class into my Xcode project and I'm getting the error of:
Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (7) beyond bounds (0) for section (0).'
The code where the crash happens is here:
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (!self.currentWindow.hidden && !_changingOrientation) {
[self.overlayView resetOverlayView];
CGPoint targetContentOffset = scrollView.contentOffset;
UITableView *tv = (UITableView*)scrollView;
NSIndexPath *indexPathOfTopRowAfterScrolling = [tv indexPathForRowAtPoint:targetContentOffset];
[self setupPhotoForIndex:indexPathOfTopRowAfterScrolling.row];
}
}
The crash seems to happen as soon as I exit the ViewController
where this is implemented?
Upvotes: 3
Views: 13974
Reputation: 566
Reload the TableView
data before calling scrollToRowAtIndexPath()
.
[contentTableView reloadData];
Upvotes: 1
Reputation: 1708
I received this error when I neglected to set the tableview's Delegate and DataSource; so it seems that nil
is also "out of bounds".
Xcode:6.4, iOS:8.x
Upvotes: 0
Reputation: 12344
The error tells you that your table does not have any row at index 7. It means that your table view consists of 7 rows and maximum range of indexPath.row can be 6 (because row index of a UITableView starts from 0). Whenever you will call a row at index path beyond range of the table, it will throw an error.
Upvotes: 9