I have done many approach on changing font colors from a tableView cell. apparently both method failed. Unless I am doing it wrongly, then I need some help to correct it. Here is the code I found online to change the font color.
[[cell textLabel] setTextColor:[UIColor colorWithRed:255.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1]];
I placed that line in the cellForRowAtIndexPath method and it did not work. Next, I searched this page and found another method to change font colors: tableView:willDisplayCell:forRowAtIndexPath: I copied and paste the setTextColor method into the willDisplayCell method and it did not work either. Below is the source code on which how I attempted and failed:
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"ApplicationCell";
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"PharmacyCell" owner:self options:nil];
cell = tempCell;
self.tempCell = nil;
}
//cell.useDarkBackground = (indexPath.row % 2 == 0);
HealthWellness *objHealth = [self.maHealthArray objectAtIndex:indexPath.row];
cell.strPharmacyName = [objHealth.healthName stringByReplacingOccurrencesOfString:@"|" withString:@""];
[[cell textLabel] setTextColor:[UIColor colorWithRed:255.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1]];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
tableView:willDisplayCell:forRowAtIndexPath:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
[[cell textLabel] setTextColor:[UIColor colorWithRed:255.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1]];
}
ApplicationCell.h
@interface ApplicationCell : UITableViewCell{
//variable declaration
BOOL useDarkBackground;
BOOL useMenuBackground;
NSString *strPharmacyName;
UIImage *pharmacyIcon;
NSString *strStoreName;}
//setting property
@property BOOL useDarkBackground;
@property BOOL useMenuBackground;
@property(retain) NSString *strPharmacyName;
@property(retain) UIImage *pharmacyIcon;
@property(retain) NSString *strStoreName;
ApplicationCell.m
- (void)setUseDarkBackground:(BOOL)flag{
if (flag != useDarkBackground || !self.backgroundView)
{
useDarkBackground = flag;
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:useDarkBackground ? @"BGDark" : @"BGLight" ofType:@"png"];
UIImage *backgroundImage = [[UIImage imageWithContentsOfFile:backgroundImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
self.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.backgroundView.frame = self.bounds;
}}
- (void)setUseMenuBackground:(BOOL)flag{
if (flag != useDarkBackground || !self.backgroundView)
{
useDarkBackground = flag;
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:useDarkBackground ? @"BGDark" : @"BGLight" ofType:@"png"];
UIImage *backgroundImage = [[UIImage imageWithContentsOfFile:backgroundImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
self.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.backgroundView.frame = self.bounds;
}}
You seem to be using a custom subclass of
UITableViewCelland since you mention that there is a lot going on in theApplicationCellclass. I am guessing that your subclass isn’t making use of thetextLabelfield since your changes aren’t reflecting on the UI.Check for the property outlet that is being displayed on screen from your
ApplicationCellinterface declaration & theNIBfile. Once you’ve the appropriate property outlet, change its property.