Bronze Challenge


#1

A simple solution would be adding in the tableView:cellForRowAtIndexPath: method an if statement to determine the appropriate text colour.
I’m concerned that this would have broken the MVC as the colour thing is of view layer which is possibly dealt in the cell object.

[code]- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BNRItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@“BNRItemCell” forIndexPath:indexPath];
BNRItem *item = [BNRItemStore sharedStore].allItems[indexPath.row];
cell.nameLabel.text = item.itemName;
cell.serialNumberLabel.text = item.serialNumber;
cell.valueLabel.text = [NSString stringWithFormat:@"$%d", item.valueInDollars];
cell.thumbnailView.image = item.thumbnail;
__weak BNRItemCell *weakCell = cell;
cell.actionBlock = ^{
BNRItemCell *strongCell = weakCell;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
UIImage *image = [[BNRImageStore sharedStore] imageForKey:item.itemKey];
if (!image)
return;
CGRect rect = [self.view convertRect:strongCell.thumbnailView.bounds fromView:strongCell.thumbnailView];
BNRImageViewController *imageViewController = [[BNRImageViewController alloc] init];
imageViewController.image = image;
self.imagePopover = [[UIPopoverController alloc] initWithContentViewController:imageViewController];
self.imagePopover.delegate = self;
self.imagePopover.popoverContentSize = CGSizeMake(600, 600);
[self.imagePopover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
};

if (item.valueInDollars >= 50) {
    cell.valueLabel.textColor = [UIColor greenColor];
} else {
    cell.valueLabel.textColor = [UIColor redColor];
}

return cell;

}[/code]