Q:

How to populate collection view with dynamic content

I apologise if the question is a bit vague.
The problem I am having is this:
I have a collection view with 9 cells.  Each cell holds a filtered version of a UIImage and the name of the filter.  For some reason index 7(case 7 in the code) doesn't get used and it looks like index 8 (case 8)is shown twice.
Here are the relevant methods:
-(UIImage *)filteredImageFromImage:(UIImage *)image withFilterIndex:(NSUInteger)filterIndex{

    CIImage *beginImage =
    [CIImage imageWithCGImage:image.CGImage];

    // 1
    CIContext *context = [CIContext contextWithOptions:nil];

    CIFilter *filter;

    switch (filterIndex) {
        case 0:
            filter = [CIFilter filterWithName:@"CIPhotoEffectNoir" keysAndValues: kCIInputImageKey, beginImage, nil];
            break;
        case 1:
            filter = [CIFilter filterWithName:@"CIPhotoEffectMono" keysAndValues: kCIInputImageKey, beginImage, nil];
            break;
        case 2:
            filter = [CIFilter filterWithName:@"CIPhotoEffectTonal" keysAndValues: kCIInputImageKey, beginImage, nil];
            break;
        case 3:
            filter = nil;
            break;
        case 4:
            filter = [CIFilter filterWithName:@"CIPhotoEffectFade" keysAndValues: kCIInputImageKey, beginImage, nil];
            break;
        case 5:
            filter = [CIFilter filterWithName:@"CIPhotoEffectChrome" keysAndValues: kCIInputImageKey, beginImage, nil];
            break;
        case 6:
            filter = [CIFilter filterWithName:@"CIPhotoEffectProcess" keysAndValues: kCIInputImageKey, beginImage, nil];
            break;
        case 7:
            filter = [CIFilter filterWithName:@"CIPhotoEffectTransfer" keysAndValues: kCIInputImageKey, beginImage, nil];
        case 8:
            filter = [CIFilter filterWithName:@"CIPhotoEffectInstant" keysAndValues: kCIInputImageKey, beginImage, nil];
            break;
        default:
            filter = nil;
            break;
    }

    CIImage *outputImage;

    if (!filter) {
        outputImage = beginImage;
    }else{
        outputImage = [filter outputImage];
    }
    // 2
    CGImageRef cgimg =
    [context createCGImage:outputImage fromRect:[beginImage extent]];

    // 3
    UIImage *newImage = [UIImage imageWithCGImage:cgimg ];

    // 4
    CGImageRelease(cgimg);
    return newImage;

}

-(NSString *)effectNameforIndex:(NSInteger )index{

    NSString *name;

    switch (index) {
        case 0:
            name = @"noir";
            break;
        case 1:
            name = @"mono";
            break;
        case 2:
            name = @"tonal";
            break;
        case 3:
            name = @"original";
            break;
        case 4:
            name = @"fade";
            break;
        case 5:
            name = @"chrome";
            break;
        case 6:
            name = @"process";
            break;
        case 7:
            name = @"transfer";
        case 8:
            name = @"instant";
            break;
        default:
            name = @"original";
            break;
    }

    return name;

}

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return 9;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FilterCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"filterPreviewCell" forIndexPath:indexPath];
    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
    options.synchronous = YES;
    [[PHImageManager defaultManager] requestImageForAsset:self.firstAsset targetSize:cell.imageView.frame.size contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *result, NSDictionary *info) {
        if (result) {
            cell.imageView.image = [self filteredImageFromImage:result withFilterIndex:indexPath.row];
            cell.nameLabel.text = [self effectNameforIndex:indexPath.row];
        }
    }];

    cell.layer.cornerRadius = 10.0;
    cell.layer.borderColor = [[UIColor colorWithWhite:1.0 alpha:0.72]CGColor];
    cell.layer.borderWidth = 2.0;
    cell.clipsToBounds = YES;

    return cell;
}

and here is an image of the result:

Any help would be greatly appreciated
Thanks

A:

You forgot to put a break; in your case 7. That is why both cell 7 and 8 show the same data.

