码迷,mamicode.com
首页 > 其他好文 > 详细

UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃

时间:2016-04-09 18:52:53      阅读:242      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!