I am using Storyboard to create the UICollectionViewController - CollectionView - Cell(my own DasboardsViewCell) and my customer view (DashBoardView) inside cell. I wired up everything correctly and everything seems to work except when I scroll up and down. I will explain what my understanding is after I debug.
Also I have 2 views inside my DashBoardView custom view which i used "one" as main primary and other as FlipView (e.g. when user taps on cell). Since everything is wired from storyboard I dont have to registerClass for reusing.
1) In my DashboardCustomView (who has 2 other views in it as above) i do this
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
_isPrimary = YES;
//to init my 2 child views and insert to main custom view
[self initSubViewsWithInsert];
}
return self;
}
2) In my DashBoardViewCell class I do this
@synthesize dashBoardView = _dashBoardView;
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
self.backgroundColor = [UIColor colorWithWhite:0.75f alpha:0.6f];
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.borderWidth = 2.0f;
self.layer.cornerRadius = 7.0f;
}
return self;
}
// If I dont do this below I get overlapped images and data on cell when scrolling up and down
- (void)prepareForReuse
{
self.dashBoardView.mainContainerView = nil;
self.dashBoardView.flipView = nil;
}
3) Now after this I still see the custom view appears out of order and seems somewhat better than not doing "nil" on my views, but the problem is once I nil out my 2 subviews I have no defined way to reinitialize them when my collectionview controller requeus the cell and start adding my content.
i.e. I do like this cellForItemAtIndexPath
if ([cell isKindOfClass:[DashboardsViewCell class]]) {
DashboardsViewCell *dashCell = (DashboardsViewCell*) cell;
Dashboard* tmpDashboard = self.availableDashBoards[indexPath.item];
[dashCell.dashBoardView addDashboardImageViewAtPoint:tmpDashboard.identifier
usingIndexPath:indexPath];
Last line above is adding some image and text on dashboards main view which is self.dashBoardView.mainContainerView and it has already nil.
Can someone help me understand if there is defined way to do this. Also if you think I am looking at wrong problem