objective c - UIButton is 0x0000 when reload TableView in ios -
i added uibutton each uitableview row when nedd reloaddata, uibutton 0x0000. can give me suggestions? much. used code:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { /*nsstring *cellidentifier = [nsstring stringwithformat:@"%d,%d",indexpath.section,indexpath.row]; // nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [_tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) {*/ nsstring *cellidentifier = [nsstring stringwithformat:@"%d,%d",indexpath.section,indexpath.row]; uitableviewcell *cell = [_tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier] autorelease]; uilabel *pricelabel = [[uilabel alloc] initwithframe:cgrectmake(80, 0, 80, 30)]; pricelabel.backgroundcolor = [uicolor clearcolor]; pricelabel.font = [uifont fontwithname:@"helvetica" size:16]; pricelabel.font = [uifont boldsystemfontofsize:16]; pricelabel.textcolor = [uicolor darkgraycolor]; pricelabel.tag = 3000; //pricelabel.hidden = yes; pricelabel.textalignment = nstextalignmentright; [cell.contentview addsubview: pricelabel]; [pricelabel release]; uibutton * market = [[uibutton alloc] init];; [market setframe:cgrectmake(200, 6, 30, 30)]; market.tag = 4000; [market addtarget:self action:@selector(marketpressedaction:) forcontrolevents:uicontroleventtouchdown]; // [market settag:indexpath.row]; [cell.contentview addsubview:market]; } if([pricenewarray count]> 0) { uilabel *pricelbl = (uilabel*)[cell.contentview viewwithtag:3000]; pricelbl.text =[nsstring stringwithformat:@"$%@",[pricenewarray objectatindex:indexpath.row]]; if ([sellingarray count]>0) { if([[sellingarray objectatindex:indexpath.row] isequaltostring:@"2"]){ pricelbl.hidden = no; } else if([[sellingarray objectatindex:indexpath.row] isequaltostring:@"0"]){ pricelbl.hidden = yes; } } } uibutton *marketbutton = (uibutton*)[cell.contentview viewwithtag:4000]; [marketbutton settag:indexpath.row]; if([sellingarray count]>0) { nslog(@"sellingarray %@",sellingarray); if([[sellingarray objectatindex:indexpath.row] isequaltostring:@"0"]) // nothing { [marketbutton setselected:no]; [marketbutton setimage:[uiimage imagenamed:@"marketplace.png"] forstate:uicontrolstatenormal]; marketbutton.enabled = yes; } else if([[sellingarray objectatindex:indexpath.row] isequaltostring:@"2"]) // marketplace { [marketbutton setselected:yes]; [marketbutton setimage:[uiimage imagenamed:@"marketplaceselect.png"] forstate:uicontrolstatenormal]; marketbutton.enabled = yes; } } _tableview.contentinset = uiedgeinsetsmake(0, 0, 100, 0); return cell; }
i used above code, when reloaddata, data of price label changed fine marketbutton can not changed image. debug after call [_tableview reloaddata];
, marketbutton 0x0000 .
i think comparison not correct. trying compare integer string.
if asumed correct try this.
int sellingprice=0; if([[sellingarray objectatindex:indexpath.row] isequaltostring: [nsstring stringwithformat:@"%i",sellingprice]]) // nothing sellingprice=2; else if([[sellingarray objectatindex:indexpath.row] isequaltostring:[nsstring stringwithformat:@"%i",sellingprice]]) // marketplace
Comments
Post a Comment