私のアプリは、(説明に加えて) セル文字列として表示される合格/不合格の結果を受け取るテーブル ビュー行を動的に追加します。テキストで失敗した結果を受け取るセルの量を数えようとしています。私の問題は、NSLog(@"Counted times: %i", times);
それらを合計するのではなく、常に 1 を返すことです。
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);
}
更新されたコード
- (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;
}