我的模型中的数据在CollectionView sizeForItemAt中为空

时间:2019-12-18 11:00:57

标签: swift google-cloud-firestore

我正在尝试在“ MainViewController”的CollectionView中更改单元格的高度

...
//var dec
var posts = [PostModel]()
var users = [UserModel]()
var refreshControl = UIRefreshControl()
...

我正在通过loadPostsFireStoreListener()加载数据,并且运行正常。

override func viewDidLoad() {
    super.viewDidLoad()

    exploreCollectionView.delegate = self
    exploreCollectionView.dataSource = self
    exploreCollectionView.alwaysBounceVertical = true


    loadPostsFireStoreListener()
}

我正在尝试获取“ imageHeight”,但是,Swift告诉我我的“帖子”为零。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    print(posts[indexPath.row].imageHeight!)
    let height : CGFloat = posts[indexPath.row].imageHeight!
}

我确定根本上有问题,但是我不知道是什么。

0 个答案:

没有答案