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

 

 



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM