Search code examples
uicollectionviewsingle-responsibility-principle

UICollectionViewDataSource methods are not getting called when data-source is a separate class


I created a UICollectionView inside a UITableViewCell and a separate data-source class DataSource for this collection-view.

DataSource conforms to the UICollectionViewDataSource protocol and I have also assigned the dataSource of an instance of DataSource in my collection-view container class.

But none of the data-source methods in DataSource are getting called.

It was working fine before I created a separate class for UICollectionView data-source.


Solution

  • Resolved!

    It was a stupid mistake. I hadn't created the instance variable to retain the instance of DataSource in my collection-view container class, so it was getting released as soon as the method where it was getting alloc-inited finished.