2017-04-18 45 views
-2

我的代碼目前能夠更改我擁有的標籤背景。標籤從服務器更新並可能不一致地返回標籤,而是作爲一個句子而不是一個單詞。有沒有辦法將if(@"%@",[cell.lblStatus.text isEqual: @"Full"])更改爲標籤包含單詞的地方?如果'contains'代替isEqual,有沒有辦法使用?

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

希望這有助於你

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