Note that there are some explanatory texts on larger screens.

plurals
  1. POtableView cells wont change font color
    text
    copied!<p>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.</p> <pre><code>[[cell textLabel] setTextColor:[UIColor colorWithRed:255.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1]]; </code></pre> <p>I placed that line in the <code>cellForRowAtIndexPath</code> method and it did not work. Next, I searched this page and found another method to change font colors: <code>tableView:willDisplayCell:forRowAtIndexPath:</code> I copied and paste the setTextColor method into the <code>willDisplayCell</code> method and it did not work either. Below is the source code on which how I attempted and failed:</p> <h3>cellForRowAtIndexPath:</h3> <pre><code>- (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; } </code></pre> <h3>tableView:willDisplayCell:forRowAtIndexPath:</h3> <pre><code>- (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]]; } </code></pre> <h3>ApplicationCell.h</h3> <pre><code>@interface ApplicationCell : UITableViewCell{ //variable declaration BOOL useDarkBackground; BOOL useMenuBackground; NSString *strPharmacyName; UIImage *pharmacyIcon; NSString *strStoreName;} </code></pre> <p>//setting property @property BOOL useDarkBackground; @property BOOL useMenuBackground; @property(retain) NSString *strPharmacyName; @property(retain) UIImage *pharmacyIcon; @property(retain) NSString *strStoreName;</p> <h3>ApplicationCell.m</h3> <pre><code>- (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; }} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload