ios - Count number of rows that contain a string in table view always returns 1 -


my app dynamically adds table view rows receive pass/fail result displayed cell string (in addition description). im trying count amount of cells receive fail result in text. problem nslog(@"counted times: %i", times); returns 1 rather adding them up.

 cell.textlabel.text = [nsstring stringwithformat:@"appliance %@:  %@", ((circuit *)[self.circuits objectatindex:indexpath.row]).circuitreference,((circuit *)[self.circuits objectatindex:indexpath.row]).rcdtestbutton];     if(cell.textlabel.text && [cell.textlabel.text rangeofstring:@"fail"].location != nsnotfound){         cell.textlabel.textcolor = [uicolor redcolor];          nsstring *string = @"str";         int times = [[string componentsseparatedbystring:@"-"] count];          nslog(@"counted times: %i", times);      } 

updated code

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath  {    nsstring *string = @"str";    int times = [[string componentsseparatedbystring:@"str"] count];   static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];  if (cell == nil) {     cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } if (indexpath.section == 0) {     cell.textlabel.text = @"summary of appliance testing"; } else {     //appliance label text     cell.textlabel.text = [nsstring stringwithformat:@"appliance %@:  %@", ((circuit *)[self.circuits objectatindex:indexpath.row]).circuitreference,((circuit *)[self.circuits objectatindex:indexpath.row]).rcdtestbutton];     if(cell.textlabel.text && [cell.textlabel.text rangeofstring:@"fail"].location != nsnotfound){         cell.textlabel.textcolor = [uicolor redcolor];          nslog(@"counted times: %i", times);       }          cell.imageview.image = [uiimage imagenamed:@""]; } cell.accessorytype = uitableviewcellaccessorydisclosureindicator;  return cell;  } 

you have:

nsstring *string = @"str"; int times = [[string componentsseparatedbystring:@"-"] count]; 

why expect ever return other 1?

if want count number of rows meet criteria, need loop through data (not cells), , check each value in data.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -