-2

My code is currently able to change the background of a label I have. The label gets updated from a server and may return labels inconsistently and as a sentence instead of a single word. Is there a way to change if(@"%@",[cell.lblStatus.text isEqual: @"Full"]) to something where if the label contains a word?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    MartaViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
                                                      forIndexPath:indexPath];
    Object *currentHotel = [self.objectHolderArray
                                 objectAtIndex:indexPath.row];

    cell.lblStation.text = currentHotel.station;
    cell.lblStatus.text = currentHotel.status;
    NSLog(@"%@", cell.lblStatus.text);

    if(@"%@",[cell.lblStatus.text  isEqual: @"Full"])
        cell.lblStatus.backgroundColor = [UIColor redColor];
    else
        cell.lblStatus.backgroundColor = [UIColor greenColor];

    return cell;
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
BlackAperture
  • 69
  • 1
  • 8

1 Answers1

1

Hope this help you

if ([cell.lblStatus.text rangeOfString:@"Full"].location != NSNotFound) {
   NSLog(@"Contain");
   cell.lblStatus.backgroundColor = [UIColor redColor];
} else {
  NSLog(@"No Contain");
  cell.lblStatus.backgroundColor = [UIColor greenColor];
}
Luan Tran
  • 1,142
  • 7
  • 15