ios - Data being displayed in other uitableviewcells along with the selected cell -
ios - Data being displayed in other uitableviewcells along with the selected cell -
i new iphone development. have uitableview custom uitableviewcell. each cell contains labels, buttons created dynamically. functionality have display view on click of button , hide using same button. able display view on click of button. problem appears in other cells also. , on scrolling table appears @ random cells too. have maintained array mark position of selected cell, , display view based on array. info in array correct. still appears in other cells. kindly help me me issue. give thanks in advance.
following code cellforrowatindexpath
, , function called on button click
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ appdelegate *delegate = (appdelegate *) [[uiapplication sharedapplication] delegate]; int y=0; childcell *cell= [tableview dequeuereusablecellwithidentifier:nil]; [cell setselectionstyle:uitableviewcellselectionstylenone]; if (cell == nil) { rateimage = [[uibutton alloc]init]; rate =[[uibutton alloc]init]; nsstring *ratingcount; cell = [[childcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:nil]; [rateimage setbackgroundimage:[uiimage imagenamed:@"bluestar1.png"] forstate:uicontrolstatenormal]; rateimage.frame= cgrectmake(240, y, 15, 15); rateimage.tag = indexpath.row ; [rateimage addtarget:self action:@selector(rate_commentchild:) forcontrolevents:uicontroleventtouchupinside]; [cell addsubview:rateimage]; //rate count if(![ratingcount isequaltostring:@"0"]) { [rate settitle:[@"rate" stringbyappendingformat:@"(%@)", ratingcount] forstate:uicontrolstatenormal]; [rate sizetofit]; } else{ [rate settitle:@"rate" forstate:uicontrolstatenormal]; } rate.tag = indexpath.row ; [rate setfont:[uifont systemfontofsize:13.0]]; [rate addtarget:self action:@selector(rate_commentchild:) forcontrolevents:uicontroleventtouchupinside]; rate.frame = cgrectmake(250, y-2, 50, 20); [rate settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal]; [cell addsubview:rate]; cv = [[asstarratingview alloc]initwithframe:cgrectmake(190, y+10, 140, 30)]; //creat instance of custom view //[cv setbackgroundcolor:[uicolor lightgraycolor]]; cv.tag = indexpath.row ; if([delegate.constants.snssubcommentrate[indexpath.row] isequaltostring: @"0"]) { cv.hidden=true; } else { cv.hidden=false; } [cell addsubview:cv]; } homecoming cell;} -(void)rate_commentchild:(uibutton *)sender { nslog(@"entered rate function"); appdelegate *delegate = (appdelegate *)[[uiapplication sharedapplication] delegate]; uibutton *b = (uibutton *)sender; nsinteger row = b.tag ; uitableviewcell *buttoncell = (uitableviewcell *)[b superview]; uitableview* table = (uitableview *)[buttoncell superview]; nsindexpath* pathofthecell = [table indexpathforcell:buttoncell]; nslog(@"path of cell %@",pathofthecell); nslog(@"stars array %@",delegate.constants.snssubcommentrate); bool isratingalreadyvisible = false; int ratingvisibleatposition = 1; (int i=0; i<[delegate.constants.snssubcommentrate count]; i++) { if([[delegate.constants.snssubcommentrate objectatindex:i] isequaltostring:@"1"]) { isratingalreadyvisible = true; ratingvisibleatposition = i; } } if(isratingalreadyvisible == true && row != ratingvisibleatposition) { delegate.constants.snssubcommentrate[ratingvisibleatposition] = @"0"; [subcommentstable reloaddata]; } if(![delegate.constants.user_id isequaltostring:[delegate.constants.snssubcommentcreatedby objectatindex:row]]) { nslog(@"can rate comment"); //stars hidden if([delegate.constants.snssubcommentrate[row] isequaltostring:@"0"]) { delegate.constants.snssubcommentrate[row]=@"1"; rating_layout.hidden=false; } //stars visible else{ delegate.constants.snssubcommentrate[row]=@"0"; rating_layout.hidden=true; } [subcommentstable reloadrowsatindexpaths:@[pathofthecell] withrowanimation:uitableviewrowanimationleft]; [subcommentstable reloadinputviews]; } else nslog(@"can't rate comment"); nslog(@"stars array %@",delegate.constants.snssubcommentrate); }
ios uitableview
Comments
Post a Comment