2017-11-02 12 views
1

2k + 레코드가있는 UICollectionView가 있습니다. 언제든지 6-7 행만 표시되며 재사용 가능한 셀을 사용하고 있습니다. 모든 것이 잘 작동합니다.UICollectionView가 보이는 셀 이외의 셀을 더 많이로드합니다.

그러나 cellForRowAtIndexPath에서 콘솔 로그를 만들 때 초기 80 개 이상의 행이로드되고 있습니다. 그 후 첫 번째 7 행을 다시로드하고 보이는 셀만 올바르게로드합니다.

왜 초기에 80 개 이상의 행을로드합니까? 초기로드가 약간 지연됩니다.

func numberOfSections(in collectionView: UICollectionView) -> Int { 
    return 1 
} 

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return results.count 
} 

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

    print("Cell For Row -> \(indexPath)") 

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ResultCell", for: indexPath) as! ResultCell 
    cell.data = result[indexPath.item] 
    return cell  
} 

UPDATE : I 자동 크기 조정 세포를 사용했다

. 그래서 나는 적절한 CGSize 대신 UICollectionViewFlowLayoutAutomaticSize을 정의하는 시도

UICollectionViewFlowLayoutAutomaticSize estimatedItemSize을 정의했다. 그리고 여분의 세포가 적재를 중단했습니다.

+0

이상합니다. 데모 프로젝트를 만들고 저에게 링크를 줄 수 있습니까? – trungduc

+0

'prefetchDataSource'를 사용하고 있습니까? – Jack

+0

@ 잭 예 .. 할 ..하지만 나는 그것을 제거하고 시도. 그것도 여전히 동일하다. –

답변