我刚刚在我的 Xcode 项目中实现了 AGPhotoBrowser
类,但出现以下错误:
Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (7) beyond bounds (0) for section (0).'
发生崩溃的代码在这里:
#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];
}
}
崩溃似乎是在我退出实现此功能的 ViewController
时立即发生的?
最佳答案
错误告诉你你的表在索引 7 处没有任何行。这意味着你的 TableView 由 7 行组成,indexPath.row 的最大范围可以是 6(因为 UITableView 的行索引从 0 开始) .每当您在索引路径中调用超出表范围的行时,它都会引发错误。
关于ios - Xcode - [UITableView _contentOffsetForScrollingToRowAtIndexPath :atScrollPosition:]: row (7) beyond bounds (0) for section (0).',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26034814/