-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;
}
0

1 Answer 1

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];
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.