ios - UIButton overlapping and hidden unexpectedly inside UITableViewCell -
i have created auibutton
programmatically inside customuitableviewcell
, no. ofuibuttons
inside cell dynamic , @ first looks working perfect when open collapsed cell , scroll table view uibutton
overlap each other , if scroll more the uibutton
in view outside screen become hidden when thy come screen area here image looks like.
i not posting code here because big , don't know part should include here. if asked post particular code here.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; interesttableviewcell *cell = (interesttableviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; nsstring *category= (nsstring *)[self.itemsintable objectatindex:indexpath.row]; nsmutablearray *subcat =[[nsmutablearray alloc] init]; nsarray *keys = [cat allkeys]; id akey = [keys objectatindex:indexpath.row]; subcat = [cat objectforkey:akey]; cell.btngrouptap.tag = indexpath.row+10000; nsarray *count=(nsarray *)subcat; int xoffset; int yoffset = 0; for(int i=0; i<count.count;i++) { if(i==0) { xoffset=0; } else { if(i%2 == 0) { xoffset = 0; } else { xoffset = 150; } } if(i==0) { yoffset = 0; } else { if(i%2==0) { yoffset = yoffset+45; } } nsstring *sel = subcat[i][@"selected"]; nsstring *key =subcat[i][@"key"]; uibutton *button = [uibutton buttonwithtype:uibuttontypecustom]; uiimage *image; if(![sel boolvalue]) { image = [uiimage imagenamed: @"unchecked.png"]; } else { image = [uiimage imagenamed: @"checked.png"]; } uiimageview *imageview = [[uiimageview alloc] initwithframe:cgrectmake(29,18,20,20)]; [imageview setimage:image]; uilabel *lbl1 = [[uilabel alloc] init]; [lbl1 setframe:cgrectmake(0,5,100,20)]; lbl1.backgroundcolor=[uicolor clearcolor]; lbl1.textcolor=[uicolor blackcolor]; lbl1.frame = cgrectmake(40,0,100,40); lbl1.numberoflines =0; [lbl1 setfont:[uifont fontwithname:@"roboto-light" size:12]]; lbl1.text= subcat[i][@"value"]; button.tag= [key integervalue]; [button settitle:@"" forstate:uicontrolstatenormal]; button.imageview.contentmode = uiviewcontentmodescaleaspectfit; [button setbackgroundimage:image forstate:normal]; cgrect screenrect = [[uiscreen mainscreen] bounds]; cgfloat screenwidth = screenrect.size.width; button.frame = cgrectmake(xoffset,20+yoffset,(screenwidth/2)-40,40); [button addtarget:self action:@selector(checkaction:) forcontrolevents:uicontroleventtouchupinside]; [button addsubview:lbl1]; [cell.containerview addsubview:button]; [cell.containerview bringsubviewtofront:button]; } cell.containerview.hidden=yes; cell.lblcategory.text = category; return cell; }
note: used [tableview beginupdates];[tableview endupdates];
in didselectrowatindexpath
.
the thing using reusable cells. think of shopping cart in market. never know if new one, maybe 1 products in it. should clean cell in cellforrowatindexpath
, proceed code.
#edit seems cleaning containerview should help. like:
interesttableviewcell *cell = (interesttableviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; [[cell.containerview subviews] makeobjectsperformselector:@selector(removefromsuperview)];
Comments
Post a Comment