UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃

 

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]>0&&[selfnumberOfRowsInSection: 0]>0){
        [selfscrollToRowAtIndexPath: [NSIndexPathindexPathForRow: 0inSection: 0]atScrollPosition: UITableViewScrollPositionTopanimated: animated];
    }
}

-(void)scrollToBottomWithAnimated: (BOOL)animated{
    if([selfnumberOfSections]>0){
        NSIntegerlastSectionIndex=[selfnumberOfSections]-1;
        NSIntegerlastRowIndex=[selfnumberOfRowsInSection: lastSectionIndex ]-1;
        if(lastRowIndex>0){
            NSIndexPath*lastIndexPath=[NSIndexPathindexPathForRow: lastRowIndexinSection: lastSectionIndex];
            [selfscrollToRowAtIndexPath: lastIndexPathatScrollPosition: UITableViewScrollPositionBottomanimated: animated];
        }
    }
}@end

 

 


posted @ 2016-04-09 17:42  frounk  阅读(5528)  评论(0)    收藏  举报