有没有办法使用if'contains'而不是isEqual?

时间:2017-04-18 01:46:21

标签: ios objective-c

我的代码目前能够更改我拥有的标签的背景。标签从服务器更新,并且可能不一致地返回标签,而不是单个单词。有没有办法将if(@"%@",[cell.lblStatus.text isEqual: @"Full"])更改为标签中包含单词的内容?

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

1 个答案:

答案 0 :(得分:1)

希望这能帮到你

if ([cell.lblStatus.text rangeOfString:@"Full"].location != NSNotFound) {
   NSLog(@"Contain");
   cell.lblStatus.backgroundColor = [UIColor redColor];
} else {
  NSLog(@"No Contain");
  cell.lblStatus.backgroundColor = [UIColor greenColor];
}