Ios Xcode-[UITableView\u contentOffsetForScrollingToRowatineXPath:atScrollPosition:]:第(7)行超出第(0)节的界限(0)。&x27;
我刚刚在我的Xcode项目中实现了Ios Xcode-[UITableView\u contentOffsetForScrollingToRowatineXPath:atScrollPosition:]:第(7)行超出第(0)节的界限(0)。&x27;,ios,objective-c,xcode,uiscrollview,uicollectionview,Ios,Objective C,Xcode,Uiscrollview,Uicollectionview,我刚刚在我的Xcode项目中实现了AGPhotoBrowser类,我得到了以下错误: Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (7) beyond bounds (0) for section (0).' 发生崩溃的代码如下所示: #
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处没有任何行。这意味着表视图由7行组成,indexath.row的最大范围可以是6(因为UITableView的行索引从0开始)。无论何时在索引路径调用超出表范围的行,它都会抛出一个错误 当我忽略设置tableview的委托和数据源时,我收到了这个错误;因此,似乎nil
也是“出界”的
Xcode:6.4,iOS:8.x在调用
ScrollToRowatinexPath()
之前重新加载TableView
数据
我设法修好了-谢谢你!这是因为我使用的datasource委托正在从NSMutableArray提取tableview中的项目数,所以我这样做了:-(void)viewWillEnglish:(BOOL)animated{assets=nil;ag=nil;}:)
[contentTableView reloadData];