views:

31

answers:

1

I'm trying to change the text of a custom UITableViewCell based on whether the text says Closed or not. However, when the text is Closed, the color will not change. Here is a code snippet. http://pastie.org/1078690 Thanks.

A: 

Simple equality does not work for NSString objects. Instead of

if ([dict objectForKey:@"status"] == @"Closed") {

do

if ([[dict objectForKey:@"status"] isEqualToString:@"Closed"]) {

That will work - but I bet you could find a more efficient way of conditionally changing color than checking a string inside cellForRowAtIndexPath. Trouble is this method will be called often. You are reusing cells, which is an efficiency measure, that's good. But then you do something relatively expensive like a string comparison - how about adding a BOOL that could be checked instead, and setting it when you decide on the cell's text?

Adam Eberbach