首页 > 其他 > 详细

UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃

时间:2016-04-09 18:50:25      阅读:291      评论:0      收藏:0      [点我收藏+]
 

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

 

 


UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃

原文:http://www.cnblogs.com/frounk/p/5372183.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!