JSA986
JSA986

Reputation: 5936

Count how many times a word appears in table view row

In my Table view I am adding rows dynamically via a button press.

The detailTextLabel.text varies depending on a pass or fail result obtained in another view

Im trying to figure out how to best check how many rows contain the word "Fail"

I thought maybe add a bool and count how many times flag is raised? However not sure how to count how many times a bool == YES?

 if(cell.textLabel.text && [cell.detailTextLabel.text rangeOfString:@"Fail"].location != NSNotFound){


        //count total amount of rows that  detailTextLabel.text == failed, need to count here?

 }

Or can I check all the rows self.circuits.count for the word fail perhaps?

Upvotes: 0

Views: 100

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130212

Well, as opposed to iterating over all the objects to track which ones contain "fail" and which don't, why not just check for this condition when you add the row. Then, if it does contain "fail" you can just increment a number (which you can store where ever you want) and you can keep track of the total "fails".

self.someNumberToRemember ++ ;

Upvotes: 1

Related Questions