简体   繁体   English

UICollectionView.reloadData()不会触发UICollectionDataSource方法

[英]UICollectionView.reloadData() do NOT trigger UICollectionDataSource methods

Here is the code, where i set DataSource for CollectionView: 这是代码,在其中我为CollectionView设置了数据源:

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        collectionView.dataSource = ProductDataSource(products: createAllProductsList())
        collectionView.reloadData()
    }

DataSource class is conform to UICollectionViewDataSource protocol. DataSource类符合UICollectionViewDataSource协议。 Code compiles with no troubles. 代码编译没有麻烦。 But i see empty collection view instead of my 5 elements. 但是我看到的是空集合视图,而不是我的5个元素。 ReloadData don't trigger methods from DataSource. ReloadData不会触发DataSource中的方法。

Swift 3, XCode 8 Swift 3,XCode 8

Create an instance variable of ProductDataSource in the current class and then set it as data source that will fix the issue. 在当前类中创建ProductDataSource的实例变量,然后将其设置为可解决此问题的数据源。 The object does not have a strong pointer to it in the current case and hence the data source gets nullified. 在当前情况下,该对象没有指向该对象的强大指针,因此数据源将无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM