UICollectionViewDelegate not firing

237 views Asked by At

I have created a UICollectionView and manually implemented the datasource and delegate protocols, assigned them to the datasource and delegate properties on the view and supplied a custom flow layout implementation - but I can't seem to get the

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

delegate calls to fire.

I have an example project that uses a UICollectionViewController ... but in my case, I really can't, nor do I want to create a view controller or push it on the stack. I've got the items drawing correctly. I've customized the cells. I've extended the flow layout and customized it so the grid is correct - but tapping on any of the cells fails to fire the delegate selection methods.

Just wondering if there is was something else obvious I was missing.

1

There are 1 answers

0
Michael Lorenzo On

Do you programmatically assign the delegate and data source?

[collectionView setDelegate:self];
[collectionView setDataSource:self];
//or.... (i dont find this method safe or consistent
collectionView.delegate = self;
collectionView.dataSource = self;

edit: You may also want to check if you are referencing the right view for the delegates. If you insert the collection view into a UIView, and you have delegate methods on the view controller, make sure to reference the correct object. If you have touch events, they may also be blocking that call.