I have 2 collection views on one screen, and I have a data source and a delegate implemented for both in the same controller. However, delegate methods such as didSelectItemAtIndexPath are called only for it.
Additional Information:
- Both collection views have a cell with an image.
- AllowSelection and UserInteractionEnabled are set to true in both views of the collection.
- User engagement enabled on images
- The delegate and data source are set in the storyboard from both collection views to the view controller.
- Collection views are displayed correctly.
Both collection views have the same setting, but only one delegate works. Do you have any hints that could be customized?
Collection views are inside a scroll view. Could this be somehow related?
EDIT 2:
Project with the same problem: https://github.com/iagomr/ProblemWithAutoLayout
EDIT 1:
Somehow this is due to the limitations of auto-detection, because if I attach the bottom view of the collection to the bottom of the screen, and not to the bottom of another collection view, it will start working.
All this is due to the fact that I need to build a high screen and add everything to the view as a scroll of 1000 points.
the code:
//MARK: - CollectionView Delegate func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { println("Called") } //MARK: - CollectionView DataSource func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if collectionView == thisCV { return 1 } else if collectionView == thisOtherCV{ return 1 } } func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { return 1 } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { if collectionView == "thisCV" { if let thisCell = collectionView.dequeueReusableCellWithReuseIdentifier("thisCell", forIndexPath: indexPath) as? thisCollectionViewCell { thisCell.image = image return thisCell } } else if collectionView == "thisOtherCV"{ if let thisOtherCell = collectionView.dequeueReusableCellWithReuseIdentifier("thisOtherCell", forIndexPath: indexPath) as? OtherCollectionViewCell { thisOtherCell.image = image return thisOtherCell } } return UICollectionViewCell() }
source share