Ich versuche, eine CollectionView mit Self-Sizing und Unendlich Scroll, aber wenn ich die referenceSizeForFooterInSection
Methode meine Zellen werden nicht angezeigt.Warum kann ich die referenceSizeForFooterInSection von UICollectionViewFlowLayout mit EstimateItemSize nicht verwenden?
Wenn ich die estimateItemSize-Eigenschaft entfernen und die ItemSize-Eigenschaft festlegen, werden die Zellen angezeigt.
Was ist falsch in meinem Code?
Mein 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)
}
}
Dank.
Haben Sie die Methode 'collectionView (_: layout: sizeForItemAt:)' aus dem Protokoll 'UICollectionViewDelegateFlowLayout' implementiert? –
Nein, ich verwende die 'geschätztItemSize', um die Größe in einer Unterklasse von' UICollectionCell' zu definieren. –