2017-05-05 4 views
0

셀프 크기 조정 및 무한 스크롤을 사용하여 collectionView를 만들려고하지만 referenceSizeForFooterInSection 메서드를 설정하면 셀이 표시되지 않습니다.EstimateItemSize와 함께 UICollectionViewFlowLayout에서 referenceSizeForFooterInSection을 사용할 수없는 이유는 무엇입니까?

estimateItemSize 속성을 제거하고 ItemSize 속성을 설정하면 셀이 표시됩니다.

내 코드가 잘못 되었나요?

내 VC :

override func viewDidLoad() { 
    super.viewDidLoad() 

    // Set explorerTableView 
    setupExplorerCollectionView() 

    // load presenter viewDidLoad 
    presenter.viewDidLoad() 
} 


func setupExplorerCollectionView() { 
    // Set flow layout 
    if let flowLayout = explorerCollectionView.collectionViewLayout as? UICollectionViewFlowLayout { 
     flowLayout.estimatedItemSize = CGSize(width: self.view.frame.width, height: 398) 
     flowLayout.minimumLineSpacing = 0 
     flowLayout.scrollDirection  = .vertical 
    } 


    // Set delegate & dataSource 
    explorerCollectionView.dataSource = self 
    explorerCollectionView.delegate = self 

    // Register cells 
    explorerCollectionView.register(ExplorerCell.self) 
    explorerCollectionView.registerView(LoadingCell.self, for: UICollectionElementKindSectionFooter) 
} 

extension ExplorerViewController: ExplorerView { 

func loadExplorerData(_ stories: [Story]) { 
    self.stories.append(contentsOf: stories) 
    self.explorerCollectionView.reloadData() 
} 

func showNoContentView() { 
    // 
} 

extension ExplorerViewController: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { 

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

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    if indexPath.item == stories.count - 1 { 
     if loadMore == .haveMore { 

     } 
    } 

    let cell = collectionView.dequeueReusableCell(for: indexPath) as ExplorerCell 
    cell.setup(with: stories[indexPath.item]) 
    return cell 
} 

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 
    var footer: LoadingCell! 

    if (kind == UICollectionElementKindSectionFooter) && (loadMore != .finished){ 
     footer = collectionView.dequeueReusableView(of: kind, for: indexPath) as LoadingCell 
     footer.setup() 
    } 

    return footer 
} 

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize { 
    return (loadMore == .finished) ? CGSize.zero : CGSize(width: self.view.frame.width, height: 50) 
} 
} 

감사합니다.

+0

어디에서나 'UICollectionViewDelegateFlowLayout' 프로토콜의'collectionView (_ : layout : sizeForItemAt :)'메소드를 구현 했습니까? –

+0

아니요,'estimatedItemSize'를 사용하여'UICollectionCell'의 하위 클래스에서 크기를 정의하고 있습니다. –

답변

0

collectionView(_:layout:sizeForItemAt:)을 사용하여 각 셀의 콘텐츠 크기를 계산했습니다.