UITableViewCell selected shadow color on deselection - iphone

I have a standard UITableView. I want to set the shadowColor of the cell's textLabel to [UIColor whiteColor], but only when the cell is touched. For that, I'm using the following code. It's a custom UITableViewCell subclass that overrides setSelected/setHighlighted:
#implementation ExampleTableViewCell
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
[self setShadowColorSelected:selected];
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
[self setShadowColorSelected:highlighted];
}
- (void)setShadowColorSelected:(BOOL)selected {
if (selected) {
self.textLabel.shadowColor = [UIColor blackColor];
}else {
self.textLabel.shadowColor = [UIColor whiteColor];
}
}
#end
My problem with this approach is that, on deselection, the cell has a very short period where both the label's text and shadow are white. See this screenshot, which was taken in the exact moment of deselection:
It's basically the same approach as in these two posts:
UILabel shadow from custom cell selected color
Removing text shadow in UITableViewCell when it's selected
I'm using the approach of the accepted answer in the latter question.
I have created a very very simple code project and uploaded it to github. It shows off my problem. It's just a UITableViewController that displays a single cell.
Apart from that, there's nothing fancy. UITableView delegate methods:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[ExampleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = #"test";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; //setting this to NO doesn't work either!
}
Any ideas?

If I understood the problem, you need to display the shadow color until the cell selection is animated to be gone. I'm not sure what is incorrect in the way you tried, more straightforward solution works fine though.
Please note, you'll need to remove observer once it's not needed.
ExampleTableViewCell.h
#interface ExampleTableViewCell : UITableViewCell {
}
- (void) setSelectionShadowOfColor:(UIColor *) selColor;
#end
ExampleTableViewCell.m
#implementation ExampleTableViewCell
- (void) setSelectionShadowOfColor:(UIColor *) selColor {
self.textLabel
[self addObserver:self
forKeyPath:#"textLabel.highlighted" // not isHighlighted as that is a getter name of the highlighted property
options:NSKeyValueObservingOptionNew
context:NULL];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
BOOL isHighlighted = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
if (isHighlighted) {
self.textLabel.shadowColor = [UIColor blackColor];
} else {
self.textLabel.shadowColor = [UIColor whiteColor];
}
}
#end
ExampleTableViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
ExampleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // note the type ExampleTableViewCell is used here to avoid the interface lookup mess
if (!cell) {
cell = [[ExampleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell setSelectionShadowOfColor:[UIColor blackColor]];
}
cell.textLabel.text = #"test";
return cell;
}

Add the below to your UITableViewDelegate:
NSIndexPath *selectedIndex;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[ExampleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = #"test";
if(indexpath == selectedIndex)
{
cell.textlabel.shadowColor = [UIColor blackColor];
}
else
{
cell.textlabel.shadowColor = [UIColor whiteColor];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView beginUpdates];
selectedIndex = indexpath;
[self.tableView endUpdates];
}

This is the best I was able to do:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:NO];
[self setShadowColorSelected:selected];
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:YES];
[self setShadowColorSelected:highlighted];
}
- (void)setShadowColorSelected:(BOOL)selected {
[self.textLabel setBackgroundColor:[UIColor clearColor]];
if (selected)
{
[self.textLabel setTextColor:[UIColor whiteColor]];
[self.textLabel setShadowColor:[UIColor blackColor]];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView transitionWithView:self.textLabel duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
if (selected)
{
[self.textLabel setTextColor:[UIColor whiteColor]];
[self.textLabel setShadowColor:[UIColor blackColor]];
}
else
{
[self.textLabel setTextColor:[UIColor blackColor]];
[self.textLabel setShadowColor:[UIColor whiteColor]];
}
} completion:nil];
}
else
{
[self.textLabel setTextColor:[UIColor blackColor]];
[self.textLabel setShadowColor:[UIColor whiteColor]];
}
}

Here is a simple way to accomplish what you want:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.textLabel.shadowColor = [UIColor blackColor];
[super touchesBegan:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.textLabel.shadowColor = [UIColor whiteColor];
[super touchesEnded:touches withEvent:event];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
self.textLabel.shadowColor = [UIColor whiteColor];
[super touchesCancelled:touches withEvent:event];
}

I guess you should need to animate the changing of the text/shadow color with the same duration that UITableView uses to animate selection/deselection. In my understanding, you change the text/shadow color at the exact moment that the tableView begins animating the (dis)appearing of the selection highlight, so what you get is that your colors change momentarily, while the selection highlight takes some time to animate from one state to another
Try something like this:
__block UIColor *newShadowColor = selected ? [UIColor blackColor] : [UIColor whiteColor];
[UIView animateWithDuration:0.2
animations:^{
/* change your label/shadow color here. */
self.textLabel.shadowColor = newShadowColor;
}
completion:^(BOOL finished){
/* this is where the cell is no longer selected
or highlighted. You may do some additional style changes to your
label here */ }];

I had the same issue. All solutions I looked at required subcassing / too much additional code.
What I did in the end is to create a second UILabel underneath the primary UILabel to act as a shadow.
Don't set shadows on your primary and shadow labels. For the shadow label, set the 'Normal Color' to what you wanted your shadow color to be and set the highlighted color to 'Clear Color'.
Obviously you have to update the shadow label each time you update the primary label. Not a big price to pay in many cases.
Hope that helps!

According to my understanding you can eliminate this issue by changing the color of the tableview by using following code with the color needed
[tableView setBackgroundColor:[UIColor "GrayColor"]];

I was also facing the same problem.
Instead of using default label, you can use UIButton and your problem will be solved.
Put custom button in cell.
My requirements were solved. It might help you.

Related

Problems Making a TableView Fade

Using UIView animateWithDuration, I'm setting a UITableView alpha to 0 so that it fades away in a disappearing animation. However, I'm noticing that when the UITableView fades, there are areas on each cell that turn black before fading. If there is an image, the whole area behind it turns black while fading, and usually the inset space on both the left and right edge turn black. I've tried setting all of the background colors of the UITableViewCell subviews to white and it still doesn't work.
This tableview is not embedded in a UITableViewController. Instead, it's a separate floating tableView that I'm using as a menu.
Here is an example of what happens when it's fading:
Here is the code I'm using as well
[UIView animateWithDuration:ImageViewControllerBarsAnimationDuration delay:0 options: UIViewAnimationOptionAllowUserInteraction animations:^
{
if (self.menu.superview)
{
self.menu.alpha = 0;
}
}
completion:^(BOOL finished)
{
if (self.menu.superview)
{
[self.menu removeFromSuperview];
self.menu.alpha = 1;
}
}];
+
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (tableViewCell == nil)
{
tableViewCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
}
[[tableViewCell textLabel] setFont:[UIFont fontWithName: #"Helvetica-Bold" size: 17]];
[[tableViewCell textLabel] setText: [self.menuItems objectAtIndex:0]];
[[tableViewCell imageView] setImage: [self.menuItems objectAtIndex:1]];
return tableViewCell;
}
DTS gave me a solution to this, have to do the following:
self.myTableView.backgroundView = nil;
self.myTableView.backgroundColor = [UIColor clearColor];
Then inside of cellForRowAtIndexPath method have to do this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kOneCellID = #"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kOneCellID];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kOneCellID] autorelease];
cell.backgroundView = [[UIView alloc] init];
cell.backgroundView.backgroundColor = [UIColor whiteColor];
}
...
}
What is self.menu? If you put tableView in its place it works exactly fine.
[UIView animateWithDuration:ImageViewControllerBarsAnimationDuration delay:0 options: UIViewAnimationOptionAllowUserInteraction animations:^
{
if (tableView.superview)
{
tableView.alpha = 0;
}
}
completion:^(BOOL finished)
{
if (tableView.superview)
{
[tableView removeFromSuperview];
tableView.alpha = 1;
}
}];

can't change UITableViewCell background color

I have UITableViewCell that fits on UITableView, but somehow I can't change the background color when entering editing style mode.. I've tried everything on the web, search all day long, but still couldn't get it fixed (I've searched StackOverflow as-well). please, help me.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
MainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray* views = [[NSBundle mainBundle] loadNibNamed:#"MainTableViewCell" owner:nil options:nil];
for (UIView *view in views) {
if([view isKindOfClass:[UITableViewCell class]])
{
cell = (MainTableViewCell *)view;
}
}
}
Try customizing the cell inside tableView: willDisplayCell: method, something like this:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
You need to change the tableView cell's contentView, not the cell's background view.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.contentView.backgroundColor = [UIColor redColor];
}
to have total control on the customisation of your cells, I prefer better to override the cell view,
create a new class for your cell view, that gets called by the UITableView,
later when i get to my work computer if you havent found your answer I will post some sample code,
once you see how it works is pretty easy
you could as well place an image for your cell background, and place different labels and images, buttons, textfields in custom places of your cell,
EDIT>>
the code! [is overkill just to change the background, but if you want to really customise your cell, this is the way to go!]
in your CustomCell.h
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell {
UILabel *_kLabel;
UILabel *_dLabel;
}
#property (nonatomic, retain) UILabel *kLabel;
#property (nonatomic, retain) UILabel *dLabel;
- (void) initLabels;
#end
in your CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
#synthesize kLabel = _kLabel;
#synthesize dLabel = _dLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
CGRect popUpImageBgndRect = CGRectMake(0, 0, 942, 44);
UIImageView *popUpImageBgnd = [[UIImageView alloc] initWithFrame:popUpImageBgndRect];
[popUpImageBgnd setImage:[UIImage imageNamed:#"tableCellBgnd.png"]];
popUpImageBgnd.opaque = YES; // explicitly opaque for performance
[self.contentView addSubview:popUpImageBgnd];
[popUpImageBgnd release];
[self initLabels];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,10, 200, 20);
self.kLabel.frame = frame;
frame= CGRectMake(boundsX+98 ,10, 100, 20);
self.dLabel.frame = frame;
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void) initLabels {
self.kLabel = [[[UILabel alloc]init] autorelease];
self.kLabel.textAlignment = UITextAlignmentLeft;
self.kLabel.backgroundColor = [UIColor clearColor];
self.kLabel.font = [UIFont fontWithName:#"FS Albert" size:16];
self.kLabel.textColor = [UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1];
self.dLabel = [[[UILabel alloc]init] autorelease];
self.dLabel.textAlignment = UITextAlignmentLeft;
self.dLabel.backgroundColor = [UIColor clearColor];
self.dLabel.font = [UIFont systemFontOfSize:16];
self.dLabel.textColor = [UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1];
[self.contentView addSubview:self.kLabel];
[self.contentView addSubview:self.dLabel];
}
-(void) dealloc {
[_kLabel release];
[_dLabel release];
[super dealloc];
}
#end
And in your ViewController.m
YourViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
ENJOY!!
;)
try setting the cells backgroundColor property, worked for me cell.backgroundColor=[UIColor blueColor];
Please try this, it works for me.
UIView *bgView = [[UIView alloc] initWithFrame:cell.frame];
bgView.backgroundColor = [UIColor greenColor];
cell.backgroundView = bgView;
[bgView release];
As #Westley mentioned;
You need to change the tableView cell's contentView, not the cell's background view.
This is how you should do it:
if(index == conditionYouWant)
{
cell.contentView.backgroundColor = [UIColor whiteColor];
}
else
{
cell.contentView.backgroundColor = [UIColor colorWithRed:0.925 green:0.933 blue:0.937 alpha:1.0];
}
Hope it helps you guys out
Be sure you didn't already set the content view's background color in the Storyboard. If you did, changing the cell.backgroundColor in code will make no difference, and you will go round and round in confusion (like I did).
cell.backgroundColor = [UIColor redColor];
in swift 3 you can use
cell.backgroundcolor = UIColor.white

TableView Row unable to Select

I defined my own controller with no nib file like this:
#interface EngineViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
EngineViewProperties* viewProp;
UIImageView *imgView; // image view of selected engine
NSUInteger selectedIndex;
UITableView *menu;
}
#property (nonatomic,retain) EngineViewProperties* viewProp;
- (EngineViewController *) initWithEngineViewProperties: (EngineViewProperties *) _viewProp;
- (void) dropdownMenu: (id) sender;
I created my view in loadView,with three subviews. The subview arrowBtn is helped to popup a list of search engines.
- (void)loadView {
// ...
UIButton *arrowBtn = [[UIButton alloc] initWithFrame:rect];
[arrowBtn setImage:viewProp.arrowImg forState:UIControlStateNormal];
[arrowBtn addTarget:self action:#selector(dropdownMenu:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:imgView];
[self.view addSubview:label];
[self.view addSubview:arrowBtn];
// ...
}
I create a table listing search engines in the selector dropdownMenu:
- (void) dropdownMenu: (id) sender {
UIButton *arrowBtn = (UIButton *)sender;
// ...
menu = [[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];
menu.delegate = self;
menu.dataSource = self;
menu.backgroundColor = [UIColor blackColor];
menu.allowsSelection = YES;
[self.view addSubview:menu];
[self.view bringSubviewToFront:menu];
[menu release];
}
And I implemented
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
as usual.
But the result is that the menu popup happily,but I can do nothing with the cells.I clicked the cells,but no response.Those methods like "didSelectRowAtIndexPath" can not be called.
Sorry to paste up so much codes one time.But I really need help.I don't know what is the problem.Please forgive me for my poor English and low development skill in Iphone.And thanks a lot if you give me a little suggestions.
//Added-------------------------
"numberOfRowsInSection" is simple:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [viewProp.txtArray count];
}
and another method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MenuItems = #"MenuItems";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MenuItems];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: MenuItems] autorelease];
}
NSUInteger row = [indexPath row];
cell.imageView.image = [viewProp.imgArray objectAtIndex:row];
cell.textLabel.text = [viewProp.txtArray objectAtIndex:row];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont systemFontOfSize:12.0];
cell.selectionStyle = UITableViewCellSelectionStyleNone; // Blue style tried,helpless too
if (row == selectedIndex) {
cell.selected = YES;
}
cell.userInteractionEnabled = YES;
return cell;
}
// Added
Strangely,when the menu firstly poped up,the default selected cell was highlighted correctly,but very quickly the highlighting disappeard.
Check if you have implemented this
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
The didSelectRowAtIndexPath will not called if this is present. One way to workaround this is set [self.view addGestureRecognizer:tap]; towards your targeted view only such as [self.svContent addGestureRecognizer:tap];.
Alternatively, check which view is touched.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ((touch.view == YourTable))
{
return NO;
}
return YES;
}
Try giving cell.selectionStyle = UITableViewCellSelectionStyleBlue in your table View data source. Also check if the userInteraction is enabled for the table view and the cells.
Are you showing any data in the table have you implemented
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
in you viewController??
Seems that you are setting the delgate property correctly, also you added the protocols to the same ViewController. So the problem can be either there is no data in the tableView for selection, or there is some View on top of tableView which is blocking you interaction with the tableView.
Use
cell.selectionStyle = UITableViewCellSelectionStyleGray;
in your
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
for your cell.
remove
cell.userInteractionEnabled = YES;
code from your file.

UITableView custom section header appears below the cells

I've a custom section header in my UITableView and I can't figure out why they are appearing bellow the UITableViewCell of the table. See the screenshots:
This is the code that creates the section header:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
return [LojaInfoHeaderView lojaInfoHeaderForSection:section withTitle:sectionTitle opened:[self sectionIsOpen:section] andDelegate:self];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return [LojaInfoHeaderView viewHeight];
}
And the section's cell are inserted or deleted when the user touches the section header:
- (void)lojaInfoHeader:(LojaInfoHeaderView *)lojaInfoHeader sectionDidOpen:(NSInteger)section {
NSArray *indexPathsToInsert = [self indexPathsForSection:section];
[self setSection:section open:YES];
[_tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationTop];
}
- (void)lojaInfoHeader:(LojaInfoHeaderView *)lojaInfoHeader sectionDidClose:(NSInteger)section {
NSArray *indexPathsToDelete = [self indexPathsForSection:section];
[self setSection:section open:NO];
[_tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
}
How can I make the section header appears above the cells? How to fix it?
Update to show how things are created
These are the class methods I'm using:
+ (CGFloat)viewHeight {
return 44.0;
}
+ (LojaInfoHeaderView *)lojaInfoHeaderForSection:(NSInteger)section withTitle:(NSString *)title opened:(BOOL)isOpen andDelegate:(id<LojaInfoHeaderDelegate>)delegate {
LojaInfoHeaderView *newHeader = [[[LojaInfoHeaderView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
newHeader.section = section;
[newHeader setTitle:title];
newHeader.delegate = delegate;
[newHeader setOpen:isOpen animated:NO];
return newHeader;
}
I found the problem. I was setting the backgroundColor using alpha (yeah, I can't believe I miss this).
Wrong code in initWithFrame:
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];
Correct code:
self.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.0];
Try to change your whole table style to be grouped instead of plain. Or change your section view to be opaque. Whatever is the design requirement.

Problem making UITableViewCell text white when selected

When my user clicks on a cell I want the text to turn white:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
lblName.textColor = [UIColor whiteColor];
lblTime.textColor = [UIColor whiteColor];
}
This works fine, but when the user selects another cell, the previous cell's text color remains white. How can I revert it back to black?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
static NSIndexPath *oldIndexPath;
UITableViewCell *cell1 = [tableView cellForRowAtIndexPath:indexPath];
UITableViewCell *cell2 = [tableView cellForRowAtIndexPath:oldIndexPath];
cell1.textLabel.textColor = [UIColor whiteColor];
cell2.textLabel.textColor = [UIColor blackColor];
oldIndexPath = indexPath;
}