2016-08-05 6 views
1

매끄러운 스크롤을 유지하기 위해 UITableView의 끝에 새로운 행을 추가하는 것이 더 좋은 옵션은 무엇입니까?UITableView 다시로드하지 않고 더 많은 테이블로드

옵션 1 - insertRowsAtIndexPaths 옵션 2 - 내가 reloadData를 사용하는 경우 reloadData

, jQuery과는 초 동안 깜박이며 부드러운 스크롤에 영향을 미친다.

사용자가 테이블을 맨 아래로 스크롤하는 동안 UITableView에서 "더 많은로드"기능을 구현하려고합니다. 웹 서비스는로드 추가 행에 대한 비동기 호출을 사용하여 데이터를 가져 오는 데 사용됩니다.

+0

옵션 1 - insertRowsAtIndexPaths는 더 많은로드 옵션으로 더 좋습니다. 애니메이션도 추가 할 수 있습니다. –

+0

insertRowsAtIndexPaths 구현을위한 몇 줄의 코드를 제공하는 데 도움을 주시기 바랍니다. – UserDev

+0

제 대답을 확인하십시오. –

답변

2

웹 서비스 응답을 받고있는 곳에서이 코드를 추가하십시오.

NSMutableArray *indexPaths = [NSMutableArray array]; 
    NSInteger currentCount = self.datasource.count; 
    for (int i = 0; i < dataToAdd.count; i++) { 
     [indexPaths addObject:[NSIndexPath indexPathForRow:currentCount+i inSection:0]]; 
    } 

    // do the insertion 
    [self.dataSource addObjects:dataToAdd]; 

    // tell the table view to update (at all of the inserted index paths) 
    [self.tableView beginUpdates]; 
    [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationLeft]; 
    [self.tableView endUpdates];