I have an array of dictionary objects and I am trying to do a simple comparison of the contents of a record inside the dictionary objects. Here is my code
- (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;
}
It is logging correctly as I am seeing the values as I scroll down the table view.
I have also tried an 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;
}
But in both cases, it is acting as if the isEqualToString:@"true"
is false and doing the second condition, when it is clearly being logged as true...
Any thoughts?