UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃

[摘要:reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (0) beyond bounds (0) for section (0). 那个毛病是传进的IndexPath已越界了。须要正在挪用之前到场判别语句,没有影响机能的情]

 

reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (0) beyond bounds (0) for section (0).

这个错误是传入的IndexPath已经越界了。需要在调用之前加入判断语句,不影响性能的情况下,在调用之前要先reloadDate

代码示例:

@implementation UITableView(ScrollToTopOrBottom)

-(void)scrollToTopWithAnimated: (BOOL)animated{
if([selfnumberOfSections]>&&[selfnumberOfRowsInSection: ]>){
[selfscrollToRowAtIndexPath: [NSIndexPathindexPathForRow: 0inSection: ]atScrollPosition: UITableViewScrollPositionTopanimated: animated];
}
} -(void)scrollToBottomWithAnimated: (BOOL)animated{
if([selfnumberOfSections]>){
NSIntegerlastSectionIndex=[selfnumberOfSections]-;
NSIntegerlastRowIndex=[selfnumberOfRowsInSection: lastSectionIndex ]-;
if(lastRowIndex>){
NSIndexPath*lastIndexPath=[NSIndexPathindexPathForRow: lastRowIndexinSection: lastSectionIndex];
[selfscrollToRowAtIndexPath: lastIndexPathatScrollPosition: UITableViewScrollPositionBottomanimated: animated];
}
}
}@end
04-15 10:36