How do I communicate from a UICell to its UICollectionView

I have subclasses of each of the following: a UIViewController managing a UICollectionView. The cells in the UICollectionView contain custom subclassess of UICollectionViewCell. I am populating it UICollectionViewCell subclasses from CoreData in - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath and all this works fine and dandy.


When the user selects a cell I pick this up in - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath and segue off to process the selected cell. This all works fine and dandy.


PROBLEM: I now want to have a checkbox on each of the UICollectionViewCells that the user can click to select the cell. After they have selected one or more cells I want them to press a UIButton on the top level UIView (managed by the UIViewController (that manages the UICollectionView) and I want a method in the UIViewController top "process" each of the selected cells one at a time. How do I communciate this info back up the line to the UIViewController?


I have a UIButton on my UICollectionViewCell (xib file) which has an outlet to the custom UICollectionViewCell. I have two images associcated with the button (unselected and selected). I toggle this in the UICollectionViewCell and this works fine. BUT when the button is pressed on the containing UIViewControllers view that says "PROCESS SELECTED ITEMS NOW" I can not see a way of communicating back to this level what was selected. Since there is a MANY to One relationship of UICollectionViewCells to the UICollectionView I can not just put an outlet from the UICollectionViewCell to the UIViewController.


It seems like such an obvious thing to want to do but I can not find any examples ??? Any help greatly appreciated.

Hi,


one option would be to add a property to your UICollectionViewCell subclass which let the collection view reads the checked / unchecked state. (By looping through the visible cells.)

BUT: If the user is able to scroll cells out of the collection view while he is still able to check / uncheck cells, you have to store the state somewhere in a data model.

I usually use the delegate pattern to achieve this. The collectionView is the delegate of each cell and on each check / uncheck the cell calls it's delegate which in turn stores the state somewhere. This way you are able to set the state when a cell scolls out and than back in.


Dirk

How do I communicate from a UICell to its UICollectionView
 
 
Q