I have a custom UICollectionViewCell that has a custom background view that is drawn using one of several color schemes. The color scheme for the background view is set in my custom initializer -(id)initWithFrame:andColourPalette: for the view.
I have a similar custom initializer in my subclass of UICustomViewCell , but I cannot figure out how to call this initializer when I set up the cell in cellForItemAtIndexPath:
Can someone help me do this? Or suggest an alternative solution for passing this Color Dictionary to a cell to go to subView?
EDIT to show more details:
This is what I have in the UICollectionView VC:
In ViewWillAppear:
[self.collectionView registerClass:[OPOLawCollectionViewCell class] forCellWithReuseIdentifier:CELL_ID]; self.colourPalette = [OPOColourPalette greenyColourPalette];
In cellForItemAtIndexPath:
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CELL_ID forIndexPath:indexPath]; OPOLawCollectionViewCell *lawCell = (OPOLawCollectionViewCell *)cell; MainLevel *level = self.collectionData[indexPath.row]; lawCell.delegate = self; lawCell.colourPalette = self.colourPalette;
In my custom UICollectionViewCell
- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) {
But this does not work - I think, because the properties are not configured.
If I change the last line to this, then it works fine:
OPOLawBook *lawBookView = [[OPOLawBook alloc]initWithFrame:CGRectMake(0, 0, 200, 265) andColourPalette:[OPOColorPalette greenyColorPalette]];
So, I think I need to use a custom intialiser here, but I can't figure out what to call it, or where ...
thanks