Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1935
Bizarre issue with cellAt:
posted

I don't know what's going on here (see attached video), but when i build the cells using the cellAt: method, instead of getting a white-filled or blue-filled star on each of the cells along the bottom, I get a fairly fixed star, and a star dancing around from cell to cell as I move the row side to side.

My code is basically this...

    -(IGGridViewCell*)gridView:(IGGridView *)gridView cellAt:(IGCellPath *)path

    {

        // Attempt to get an existing cell, or create one if not cached.

        // ...

        iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:path.columnIndex];

        

        if (path.rowIndex == 0) {

            return [self buildImageViewCellForGridViewCellAt:path withImageAndMediaItem:imageAndMediaItem];

        }

        else {

            return [self buildImageLabelingCellForGridViewCellAt:path withImageAndMediaItem:imageAndMediaItem];

        }

    }

    -(IGGridViewCell*)buildImageViewCellForGridViewCellAt:(IGCellPath*)path withImageAndMediaItem:(iRpImageAndMedia*)imageAndMediaItem

    {

        IGGridViewImageCell* theImageCell = [theGridViewFilmstrip dequeueReusableCellWithIdentifier:IMAGE_CELL];

        

        if (theImageCell == nil) {

            theImageCell = [[IGGridViewImageCell alloc] initWithReuseIdentifier:IMAGE_CELL];

        }

        theImageCell.enableZooming = NO;

        theImageCell.contentMode = UIViewContentModeScaleAspectFit;

        theImageCell.opaque = YES;

        theImageCell.imageView.image = [imageAndMediaItem pictureForViewOfSize:CGSizeMake(213, 160)];

        theImageCell.imageView.userInteractionEnabled = YES;

        [self getMarkerForCell:theImageCell imageAndMediaItem:imageAndMediaItem];

        

        [self addGestureRecognizersToCell:theImageCell];

        return theImageCell;

    }




    -(void)getMarkerForCell:(IGGridViewImageCell*)cell imageAndMediaItem:(iRpImageAndMedia*)imageAndMediaItem

    {

        if (imageAndMediaItem.isPrimary) {

            [cell addSubview:[primaryImageMarkers valueForKey:@"yes"]];

        }

        else {

            [cell addSubview:[primaryImageMarkers valueForKey:@"no"]];

        }

    }


2016-04-28_08-05-11.mp4.zip
  • 40030
    Verified Answer
    Offline posted

    Hi!, 

    Thanks for including a code snippet and a video.

    I see a couple of things in the code that are probably contributing to this issue. 

    Issue 1 - You want to make sure that you do all of your cell initialization when you create the cell. This includes, adding your gesture AND adding subviews. 

    Basically this code will recycle cells. SO when once cell leaves view, it will be used by another data item when it comes into view. 

    Issue 2 - It looks like you're reusing the same UIImageView as a subView of your cell. A view can only have one parent. So my guess is that when another cell comes into view its removing it from its current parent and adding it as a child of another cell. Thats why you're seeing stars disappear. And also why you're only seeing 1 of each type of star at any given time. Instead, you should create your imageView once per cell and add it when you first create the cell. 

    Hope this helps!

    -SteveZ