iphone - Custom TableView Cell ,check condition -
am doing custom cell tableview cell , writing condition in customcell class, if indexpath.row=0 create 2 images cell else create 3 images ,
my custom cell class
if (appdelegate.rowindex==0) { uibutton *lobjimagebutton=[uibutton buttonwithtype:uibuttontypecustom]; lobjimagebutton.frame=cgrectmake(150*0+12.5, 5, 150-10, 290 - 120+10); [lobjimagebutton setbackgroundcolor:[uicolor greencolor]]; //lobjimagebutton.imageview.contentmode = uiviewcontentmodescaleaspectfit; [self addsubview:lobjimagebutton]; uibutton *lobjimagebutton1=[uibutton buttonwithtype:uibuttontypecustom]; lobjimagebutton1.frame=cgrectmake(150*1+10+5, 5, 150-10, 170+10); [lobjimagebutton1 setbackgroundcolor:[uicolor redcolor]]; //lobjimagebutton1.imageview.contentmode = uiviewcontentmodescaleaspectfit; [self addsubview:lobjimagebutton1]; imagebuttonarray = [[nsarray alloc] initwithobjects:lobjimagebutton, lobjimagebutton1, nil]; } else { uibutton *lobjimagebutton=[uibutton buttonwithtype:uibuttontypecustom]; lobjimagebutton.frame=cgrectmake(150*0+12.5, 5, 150-10, 290 - 120+10); [lobjimagebutton setbackgroundcolor:[uicolor greencolor]]; //lobjimagebutton.imageview.contentmode = uiviewcontentmodescaleaspectfit; [self addsubview:lobjimagebutton]; uibutton *lobjimagebutton1=[uibutton buttonwithtype:uibuttontypecustom]; lobjimagebutton1.frame=cgrectmake(150*1+10+5, 5, 150-10, 170+10); [lobjimagebutton1 setbackgroundcolor:[uicolor redcolor]]; //lobjimagebutton1.imageview.contentmode = uiviewcontentmodescaleaspectfit; [self addsubview:lobjimagebutton1]; uibutton *lobjimagebutton2=[uibutton buttonwithtype:uibuttontypecustom]; lobjimagebutton2.frame=cgrectmake(150*2+10+5, 5, 150-10, 170+10); [lobjimagebutton2 setbackgroundcolor:[uicolor bluecolor]]; //lobjimagebutton1.imageview.contentmode = uiviewcontentmodescaleaspectfit; [self addsubview:lobjimagebutton2]; imagebuttonarray = [[nsarray alloc] initwithobjects:lobjimagebutton, lobjimagebutton1,lobjimagebutton2, nil]; }
here appdelegate.rowindex value setting in viewcontroller's inside cellforrowindex appdelegate.rowstauts=indexpath.row
wen run application, project executed wish , 1st cell 2 images , remaining cells 3 images , when scroll conditon mismatching , making somtime 6th cell 2 images , sumtime 3 cell 2 images , 1st cell become 3 images..
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; bsimagecell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; appdelegate.rowindex=indexpath.row; nslog(@"cell.index= %i",cell.index); if (cell == nil) { cell = [[bsimagecell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } return cell; }
the problem arises scrolling.
the problem uitableview make these cells reusable performance sake.
u have make condition in cellforrowatindexpath also.
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ nsstring* reusablecellidentifier = @""; if(indexpath.row == 0){ reusablecellidentifier = @"firstcell"; }else{ reusablecellidentifier = @"othercells"; } }
Comments
Post a Comment