ios - UICollectionView showing only one cell - which changes when the view is scrolled -
i have uicollectionview supposed show items array. have checked array - , populated right number , type of objects.
the uicollectionview shows 1 uicollectionview cell - , changes when pull cell down previous object. i've not seen behaviour before. below code:
(it's sourcetankcollectionview causing problem (and assume destination collection view cell too)
- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { if (collectionview==self.movementsindexcollectionview) { transferslistcollectionviewcell* tempcell = [collectionview dequeuereusablecellwithreuseidentifier: @"transfer list cell" forindexpath:indexpath]; if (!tempcell) { tempcell = [[transferslistcollectionviewcell alloc] init]; } movement* thismovement = [self.arrayofallmovements objectatindex:indexpath.item]; tempcell.sourcetanklabel.text = thismovement.sourcetank.tanknumber; tempcell.destinationtanklabel.text = thismovement.destinationtank.tanknumber; tempcell.layer.borderwidth = 1.5; tempcell.layer.bordercolor = [[uicolor darkgraycolor] cgcolor]; tempcell.layer.cornerradius = 4; return tempcell; } else if (collectionview==self.sourcetankscollectionview) { sourcetankcollectionviewcell* tempcell = [collectionview dequeuereusablecellwithreuseidentifier: @"source tank collection cell" forindexpath:indexpath]; if (!tempcell) { tempcell = [[sourcetankcollectionviewcell alloc] init]; } int index = indexpath.row; if (!tempcell) { tempcell = [[sourcetankcollectionviewcell alloc] init]; } tank* thissourcetank = [self.arrayofsourcetanks objectatindex:indexpath.row]; product* thissourcetankproduct = thissourcetank.tankproduct; tempcell.tanknumberlabel.text = thissourcetank.tanknumber; tempcell.tankproductlabel.text = thissourcetankproduct.name; tempcell.tankvolumelabel.text = thissourcetank.tanktotalvolume; tempcell.tankvolumegauge.percentfilled = [thissourcetank.tanktotalvolume doublevalue]/[thissourcetank.tankmaxvolume doublevalue]; //tempcell.tankvolumetotransferlabel.text = [thismovement.volume stringvalue]; //tempcell.tankvolumetransferredlabel.text = @"35000"; tempcell.transferstatuslabel.text = @"in progress"; tempcell.backgroundcolor = [uicolor darkgraycolor]; tempcell.layer.borderwidth = 1.5; tempcell.layer.bordercolor = [[uicolor whitecolor] cgcolor]; tempcell.layer.cornerradius = 8; tempcell.frame = cgrectmake(self.sourcetankscollectionview.frame.size.width * 0.05, self.sourcetankscollectionview.frame.size.width * 0.05, self.sourcetankscollectionview.frame.size.width * 0.9, 103); return tempcell; } else //if (collectionview==self.destinationtankscollectionview) { destinationtankcollectionviewcell* tempcell = [collectionview dequeuereusablecellwithreuseidentifier: @"destination tank collection cell" forindexpath:indexpath]; if (!tempcell) { tempcell = [[destinationtankcollectionviewcell alloc] init]; } tank* thisdestinationtank = [self.arrayofdestinationtanks objectatindex:indexpath.item]; product* thisdestinationtankproduct = thisdestinationtank.tankproduct; tempcell.tanknumberlabel.text = thisdestinationtank.tanknumber; tempcell.tankproductlabel.text = thisdestinationtankproduct.name; tempcell.tankvolumelabel.text = thisdestinationtank.tanktotalvolume; tempcell.tankvolumegauge.percentfilled = [thisdestinationtank.tanktotalvolume doublevalue]/[thisdestinationtank.tankmaxvolume doublevalue]; tempcell.backgroundcolor = [uicolor darkgraycolor]; tempcell.layer.borderwidth = 1.5; tempcell.layer.bordercolor = [[uicolor whitecolor] cgcolor]; tempcell.layer.cornerradius = 8; tempcell.frame = cgrectmake(self.destinationtankscollectionview.frame.size.width * 0.05, self.destinationtankscollectionview.frame.size.width * 0.05, self.destinationtankscollectionview.frame.size.width * 0.9, 103); return tempcell; } } - (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { if (collectionview == self.movementsindexcollectionview) { return self.arrayofallmovements.count; } else if (collectionview == self.sourcetankscollectionview) { return self.arrayofsourcetanks.count; } else //(collectionview == self.destinationtankscollectionview) { return self.arrayofdestinationtanks.count; } }
many help! assume easy fix!
you not supposed set frame of uicollectionviewcell. can set width , height. , should done in:
- (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath{ return cgsizemake(collectionview.frame.size.width/2.0, collectionview.frame.size.height/2.0); }
as can observe cells collection view have same frame rectangle. maybe causing problem. cells on top of each other.
tempcell.frame = cgrectmake(self.sourcetankscollectionview.frame.size.width * 0.05, self.sourcetankscollectionview.frame.size.width * 0.05, self.sourcetankscollectionview.frame.size.width * 0.9, 103);
Comments
Post a Comment