ios - Collection View Cell Size Is Not As Expected -
i'm trying make custom keyboard using storyboard. need use 2 collection views. want height , width of collection view cell height of collection view itself. constraints set properly. cell size not looking expected. same height collection view has on storyboard.
here code.
#import "mainviewcontroller.h" #import "uppercollectionviewcell.h" #import "lowercollectionviewcell.h" @interface mainviewcontroller () <uicollectionviewdelegate, uicollectionviewdatasource, uicollectionviewdelegateflowlayout> @property (weak, nonatomic) iboutlet uicollectionview *uppercollectionview; @property (weak, nonatomic) iboutlet uicollectionview *lowercollectionview; @property (strong, nonatomic) nsarray *upperdata; @property (strong, nonatomic) nsarray *lowerdata; @end @implementation mainviewcontroller - (void)viewdidload { [super viewdidload]; nslog(@"view presented"); self.lowercollectionview.delegate = self; self.lowercollectionview.datasource = self; self.uppercollectionview.delegate = self; self.uppercollectionview.datasource = self; self.upperdata = @[[[datamodel alloc] initwithtitle:@"bollywood" subtitle:nil color:[uicolor orangecolor]], [[datamodel alloc] initwithtitle:@"hollywood" subtitle:nil color:[uicolor greencolor]], [[datamodel alloc] initwithtitle:@"tollywood" subtitle:nil color:[uicolor magentacolor]]]; self.lowerdata = @[[[datamodel alloc] initwithtitle:@"news" subtitle:@"very first comment" color:[uicolor bluecolor]], [[datamodel alloc] initwithtitle:@"tasks" subtitle:@"second comment" color:[uicolor redcolor]], [[datamodel alloc] initwithtitle:@"events" subtitle:@"third comment" color:[uicolor greencolor]]]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview { return 1; } - (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { if(collectionview == self.lowercollectionview) { return self.lowerdata.count; } else if(collectionview == self.uppercollectionview) { return self.upperdata.count; } else { return 0; } } - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { if(collectionview == self.lowercollectionview) { lowercollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"lower_cv_cell" forindexpath:indexpath]; [cell setdatamodel:self.lowerdata[indexpath.row]]; [cell layoutifneeded]; return cell; } else if(collectionview == self.uppercollectionview) { uppercollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"upper_cv_cell" forindexpath:indexpath]; [cell setdatamodel:self.upperdata[indexpath.row]]; [cell layoutifneeded]; return cell; } else { return nil; } } - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath { if(collectionview == self.lowercollectionview) { cgsize size = cgsizemake(collectionview.bounds.size.height, collectionview.bounds.size.height-10); nslog(@"lower height : %@",nsstringfromcgsize(size)); return size; } else if(collectionview == self.uppercollectionview) { cgsize size = cgsizemake(collectionview.bounds.size.height, collectionview.bounds.size.height-10); nslog(@"upper height : %@",nsstringfromcgsize(size)); return size; } else { return cgsizezero; } } @end
unable figure out why cell size not expected.
Comments
Post a Comment