У меня есть массив объектов словаря, и я пытаюсь сделать простое сравнение содержимого записи внутри объектов словаря. Вот мой код
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
int timeIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString *isAvailable = [NSString stringWithString:[[timesList objectAtIndex: timeIndex] objectForKey: @"Available"]];
UITableViewCell *cell;
static NSString *CellIdentifier = @"Cell";
static NSString *availableIdentifier = @"availableCell";
static NSString *unavailableIdentifier = @"unavailableCell";
NSLog(@"%@", isAvailable);
switch ([isAvailable isEqualToString:@"true"]) {
case YES:
// or you can just use standard cells here
cell = [tableView dequeueReusableCellWithIdentifier:availableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.textColor = [UIColor greenColor];
cell.textLabel.text = [[timesList objectAtIndex: timeIndex] objectForKey: @"Time"];
break;
case NO:
cell = [tableView dequeueReusableCellWithIdentifier:unavailableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.text = [[timesList objectAtIndex: timeIndex] objectForKey: @"Time"];
break;
}
return cell;
}
Ведение журнала корректно, так как я вижу значения при прокрутке таблицы вниз.
Я также пробовал if / else
if([isAvailable isEqualToString:@"true"]){
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:availableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.textColor = [UIColor greenColor];
cell.textLabel.text = [[timesList objectAtIndex: timeIndex] objectForKey: @"Time"];
return cell;
} else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:unavailableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.text = [[timesList objectAtIndex: timeIndex] objectForKey: @"Time"];
return cell;
}
Но в обоих случаях он действует так, как будто isEqualToString:@"true"
является ложным, и выполняет второе условие, когда он явно записывается как истинный ...
Есть мысли?