i have code, "linearedtoday" uiimageview:
- (void)viewdidload { [super viewdidload]; linearedtoday = [uiimage imagenamed:@"line4.png"];} - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *myidentifier = @"myidentifier"; myidentifier = @"tblcellview"; tableviewcell *cell = (tableviewcell*)[tableview dequeuereusablecellwithidentifier:myidentifier]; if(cell == nil) { [[nsbundle mainbundle] loadnibnamed:@"tableviewcell" owner:self options:nil]; cell = tblcell; } cell.selectionstyle = uitableviewcellselectionstylenone; [[lineday objectatindex:currenttodaylinered -1] setimage:linearedtoday]; return cell; - (ibaction) change{ linearedtoday = [uiimage imagenamed:@"linea.png"]; [lineday setimage:linearedtoday]; [mytableview reloaddata]; }
it uitableview 15 custom uitableviewcell , want change image @ uiimageview, imageview "lineday", lineday present in cells, , want change image @ cells, ibaction "change" change uiimageview in last cell , not @ all....why?
yes change image in last cell because has reference of last cell, if want when creating cell in cellforrowatindexpath check bool , set image according bool. in ibaction change bool value , call reloaddata on table view reload it. -
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"test"; uitableviewcell *cellview = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cellview == nil) { cellview = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier] autorelease]; uiimageview *bgimgview = [[uiimageview alloc] initwithframe:cgrectmake(0.0f, 0.0f, 320.0f, 85.0f)]; [bgimgview settag:1]; [bgimgview setbackgroundcolor:[uicolor clearcolor]]; [cellview.contentview addsubview:bgimgview]; [bgimgview release]; } uiimageview *imgview = (uiimageview*)[cellview viewwithtag:1]; if (buttonpressed) { [imgview setimage:[uiimage imagenamed:@"listing_bg"]]; } else { [imgview setimage:[uiimage imagenamed:@"featured_listing_bg"]]; } return cellview; } - (ibaction) change{ buttonpressed = !buttonpressed; [mytableview reloaddata]; }
Comments
Post a Comment