ios - UICollectionView shows two line but I only want one line -


i meet strange mistake when use uicollectionview, @ pic below:

the third cell seems somehow show under second, , place third cell turns out empty.

enter image description here

when scroll view away , back(or reload view) , turns right:

enter image description here

here code used:

#pragma mark - uicollectionview datasource - (nsinteger)collectionview:(uicollectionview *)view numberofitemsinsection:(nsinteger)section {      return datas.count; }  - (nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview {     return 1;  }  - (uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:    (nsindexpath *)indexpath {      static nsstring *cellid = @"floorcell";     floorcollectionviewcell *cell = [cv dequeuereusablecellwithreuseidentifier:cellid     forindexpath:indexpath];     nsdictionary *dic = [datas objectatindex:indexpath.row];     cell.goodimageview.imageurl = [nsurl urlwithstring:[dic objectforkey:@"img"]];     cell.goodlabel.text = [dic objectforkey:@"title"];     return cell;  } 

and layout use uicollectionviewflowlayout, delegate layout below:

#pragma mark – uicollectionviewdelegateflowlayout - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath {     cgsize retval = cgsizemake(172 / 2.0, [floorcollectionviewcell getheight]);     return retval; }   - (uiedgeinsets)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout insetforsectionatindex:(nsinteger)section {     return uiedgeinsetsmake(0, 0, 0, 0); } 

and want know reason , how solve problem? thanks!

the code init collectionview:

    uicollectionviewflowlayout *layout = [[uicollectionviewflowlayout alloc] init];     layout.scrolldirection = uicollectionviewscrolldirectionhorizontal;     collectionview = [[uicollectionview alloc] initwithframe:cgrectmake(50, 0, 278, bottomview.frame.size.height)  collectionviewlayout:layout];     collectionview.backgroundcolor = [uicolor clearcolor];     [collectionview registerclass:[floorcollectionviewcell class] forcellwithreuseidentifier:@"floorcell"];     collectionview.datasource = self;     collectionview.delegate = self;     [bottomview addsubview:collectionview]; 

ps: think have solved problem change height of collectionview height of cell instead of height of whole gray superview. still don`t know reason, height of gray superview not big enough hold 2 cells!

the code changed :

collectionview = [[uicollectionview alloc] initwithframe:cgrectmake(50, 0, 278, [floorcollectionviewcell getheight])  collectionviewlayout:layout]; 

i don't know if there's point in answering anymore future's sake solve problem setting height constraint on collection view itself force collection view not multiline mode.this happens when have set auto-layout constraints different priorities , there more enough space collection view expand.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -