2013-09-26 3 views
2

웹 서비스를 통해 지원되는 UICollectionView가 있습니다. 처음에는 서비스에서 컬렉션 뷰로 100 개의 항목을로드합니다. 사용자가보기의 맨 아래에 도달하면 콘텐츠의 다음 "페이지"를 동적으로로드합니다.UICollectionView에 동적으로 내용 추가

이 방법이 효과적이지만 내 collectionView가 깜박 거리고 위에서 전체보기를 다시 그립니다. 보기의 맨 아래에 새로운 내용을 그리기 시작하려고합니다. 분명

- (void)insertIntoCollectionView: (int) itemCnt { 

// only do the batchupdate for NON-initial load 

if(curPage != 0) { 
// Add items to main photos array, and update collectionview using batchUpdate 
    [self.collectionView performBatchUpdates:^{ 

    // Get starting size before update 
    int resultsSize = itemCnt; 

    // Create a new array to hold the indexpath for the inserted data 
    NSMutableArray *arrayWithIndexPaths = [NSMutableArray array]; 

    // Add indexpath objects to the new array to be added to the collection view 
    for (int i = resultsSize; i < resultsSize + itemCnt; i++) { 
     [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]]; 
    } 
    // Update the collectionview 
    [self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths]; 
} 
    completion:nil]; 
} else { 
    [self.collectionView reloadData]; 
} 
curPage++; 

아무것도 다음 collectionview에 새로운 내용을 추가하기위한

코드? 그것은 기능적으로 작동하지만 깜박이고 다시 그려지면서 꽤 나 빠졌습니다.

답변

1

확인, 직접 해결할 수 있습니다. resultSize 변수에 잘못된 값을 사용하고있었습니다. for 루프는 현재 배열 수의 끝에서 시작하고 추가 한 항목 수만큼 반복하여 끝에 추가합니다. ArrayWithIndexPaths를 빌드 할 때 배열 인덱스 1의 시작 부분부터 시작하여 전체 뷰를 다시 그려야했습니다.

+0

이 문제를 해결하기 위해 수행 된 작업을 알려 주시기 바랍니다. 나도 같은 문제에 직면 해있다. 내가 어떤 코드 변경을했는지 알려주기 바란다 – Nishan29

+0

나에게이 문제에 대한 해결책을 알려주시겠습니까? – Nishan29