You are creating the dataSource as a local variable, so once setupCollectionView
exits, it goes out of scope and can be deallocated. collectionView
will only retain a weak
reference so there is nothing to prevent the deallocation.
You should create a property for your dataSource -
@property (strong,nonatomic) CustomCollectionViewDataSource *dataSource
and then use this in your setup method -
- (void)setupCollectionView:(UICollectionView*)collectionView {
self.dataSource = [[CustomCollectionViewDataSource alloc] initWithCollectionView: collectionView];
[collectionView setDataSource: self.dataSource];
[collectionView setDelegate: self];
[collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kNNReuseIdentifier];
}