我的代码目前能够更改我拥有的标签的背景。标签从服务器更新,并且可能不一致地返回标签,而不是单个单词。有没有办法将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;
}
答案 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];
}