0

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

Gaurav18ca
  • 63
  • 1
  • 5

2 Answers2

0

I'm not sure what the issue is exactly and with that code it's a bit hard to tell. If you could post the project somewhere it would be easier. Now that many things are storyboarded, it's harder to fix issues just by posting code :(

But are you using auto layout by any chance?

marciokoko
  • 4,988
  • 8
  • 51
  • 91
0

Thanks for your reply - No Im not using auto layout and I am unable to post my code here as it has grown too big now but here is what I did to solve the problem

1) I realized when cells are being refreshed (dequeue) my logic was such that I was actually maintaining state for certain cell (User taps dashboard-B from A,B,C,D etc) with my own internal state thinking that same cell will be applied to same indexPath. i.e.

a)If user taps on cell 2 - I switch to secondary view and maintains that state in my cell.

b)Now if user scrolls up and down then cells get refreshed and I releases my internal view in prepareForResuse

once i know what i was doing wrong, I have to change my approach and move the logic in controller.

I may sound obscure here but I found that I was wrong in my assumption about cell cellForItemAtIndexPath and what it supposed to do. Once I figured that out i was able to fix my design.

Gaurav18ca
  • 63
  • 1
  • 5