ios - UICollectionView inside a container view -
desc:
i have view controller holds collection view 7 cells inside of it. when display controller, works fine , displays (controller a). on controller (controller b) have container view embeds controller a, collection view.
the problem:
when running app , going controller b (that embeds controller a), controller a's sub views except of collection view. in case, instead of seeing 7 cells see 6 , after tapping on 1 of cells, last cell appears in cells row , looks (?!). collection view being redrawn , cant find reason or how fix it.
any appreciated.
edit
that flow layout, call viewdidload:
-(void) setflowlayout { bool isiphone = (ui_user_interface_idiom() != uiuserinterfaceidiompad); float basewidth = [[uiscreen mainscreen] bounds].size.width; int width; width = floor(basewidth / 7.0); float space = basewidth - (width * 7.0f); space /= 7.0; uicollectionviewflowlayout * flow = [[uicollectionviewflowlayout alloc] init]; if(isiphone) { flow.itemsize = cgsizemake(width, kcellheight); } else{ flow.itemsize = cgsizemake(width, kcellsizeipad); } flow.minimuminteritemspacing = space; flow.headerreferencesize = cgsizemake(_collectiondays.frame.size.width, kspacing); flow.footerreferencesize = cgsizezero; flow.scrolldirection = uicollectionviewscrolldirectionvertical; [_collectiondays setcollectionviewlayout:flow]; }
i use place cells in middle of collection view:
- (uiedgeinsets)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout insetforsectionatindex:(nsinteger)section{ cgfloat cellspacing = ((uicollectionviewflowlayout *) collectionviewlayout).minimuminteritemspacing; cgfloat cellwidth = ((uicollectionviewflowlayout *) collectionviewlayout).itemsize.width; nsinteger cellcount = [collectionview numberofitemsinsection:section]; cgfloat inset = (collectionview.bounds.size.width - (cellcount * (cellwidth + cellspacing))) * 0.5; inset = max(inset, 0.0); return uiedgeinsetsmake(0.0, inset, 0.0, inset); }
so no answer far, found way fix it. kept on trying solve it, , think has container resize while being drawn.
i fixed using call collection view's layoutifneeded parent view controller, in viewdidlayoutsubviews.
so if comes across it, 1 way of fixing it.
would love hear better way\explanation.
-(void)viewdidlayoutsubviews { [super viewdidlayoutsubviews]; [_collectiondays layoutifneeded]; [_collectiondays reloaddata]; }
Comments
Post a Comment