2017-04-18 2 views
-2

Mein Code ist derzeit in der Lage, den Hintergrund eines Labels, das ich habe, zu ändern. Das Label wird von einem Server aktualisiert und kann Etiketten inkonsistent und als einen Satz statt eines einzelnen Wortes zurückgeben. Gibt es eine Möglichkeit, if(@"%@",[cell.lblStatus.text isEqual: @"Full"]) in etwas zu ändern, wo das Etikett ein Wort enthält?Gibt es eine Möglichkeit zu verwenden, wenn 'contains' statt 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; 
} 

Antwort

0

Hope this helfen Ihnen

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