ios - How to add photos into UICollectionViewCell -
i have creates uicollectionview have showing white cells. have been following tutorial figure out how use delegate methods etc..
i have made point create creating custom uicollectionviewcells in example tutorial tells open story board etc.. dont have story board... have tried follow instructions create view own .xib file , cannot work.
i hoping here can me checking out delegate methods @ point.
// how load collection view uicollectionviewflowlayout *layout=[[uicollectionviewflowlayout alloc] init]; photocollectionview =[[uicollectionview alloc] initwithframe:cgrectmake(10.0, 40.0, 480.0, 713.0) collectionviewlayout:layout]; photocollectionview.datasource = self; photocollectionview.delegate = self; [self.view addsubview:photocollectionview]; [photocollectionview.layer setbordercolor: [[uicolor lightgraycolor] cgcolor]]; [photocollectionview.layer setborderwidth: 1.0]; [self.photocollectionview reloaddata]; // delegate methods #pragma mark - collectionview delegates #pragma mark -- uicollectionview datasource // 1 - (nsinteger)collectionview:(uicollectionview *)view numberofitemsinsection:(nsinteger)section { return [imagearray count]; } // 2 - (nsinteger)numberofsectionsincollectionview: (uicollectionview *)collectionview { return 1; } // 3 - (uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:(nsindexpath *)indexpath { uicollectionviewcell *cell = [cv dequeuereusablecellwithreuseidentifier:@"photocell" forindexpath:indexpath]; // think want set image cell nsdictionary *currentphotodict = [imagearray objectatindex:indexpath.row]; uiimage *imageforcollection = [uiimage imagewithdata:[currentphotodict objectforkey:@"dimage"]]; // have no idea pass imag.... cell.backgroundcolor = [uicolor whitecolor]; return cell; } #pragma mark -- uicollectionview delegate - (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath { // todo: select item } - (void)collectionview:(uicollectionview *)collectionview diddeselectitematindexpath:(nsindexpath *)indexpath { // todo: deselect item } #pragma mark –- uicollectionviewdelegate flowlayout // 1 - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath { cgsize retval = cgsizemake(210, 157+20); // add 20 labels under neath.. might need adjust this. return retval; } - (uiedgeinsets)collectionview: (uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout insetforsectionatindex:(nsinteger)section { return uiedgeinsetsmake(50, 20, 50, 20); }subview:photocollectionview]; [photocollectionview.layer setbordercolor: [[uicolor lightgraycolor] cgcolor]]; [photocollectionview.layer setborderwidth: 1.0]; [self.photocollectionview reloaddata]; as can see in collectionview:cellforitematindexpath have image ready
nsdictionary *currentphotodict = [imagearray objectatindex:indexpath.row]; uiimage *imageforcollection = [uiimage imagewithdata:[currentphotodict objectforkey:@"dimage"]]; i need know how load collectionviewcell...
any appreciated.
please try use this....
- (uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:(nsindexpath *)indexpath { uicollectionviewcell *cell = [cv dequeuereusablecellwithreuseidentifier:@"photocell" forindexpath:indexpath]; // think want set image cell nsdictionary *currentphotodict = [imagearray objectatindex:indexpath.row]; uiimage *imageforcollection = [uiimage imagewithdata:[currentphotodict objectforkey:@"dimage"]]; [cell setbackgroundcolor:[uicolor colorwithpatternimage:imageforcollection];// add image here........ // have no idea pass imag.... cell.backgroundcolor = [uicolor whitecolor]; return cell; } i hope you...
Comments
Post a Comment