ios - How to populate collection view with dynamic content -


i apologise if question bit vague.

the problem having this: have collection view 9 cells. each cell holds filtered version of uiimage , name of filter. reason index 7(case 7 in code) doesn't used , looks index 8 (case 8)is shown twice.

here 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 image of result:

enter image description here

any appreciated thanks

you forgot put break; in case 7. why both cell 7 , 8 show same data.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -