0

I have looked over the net but didn't find the answer for my situation. So I have a subclass of UITableCellView (I am try to do a cell quite similar to the cells in the Email app). I have added a label on the right side where I want to display a date using a blue color. Now, when I touch the cell, I want to change the color of the label, as the blue highlight will hide it. I have implemented thouchesBegan, Cancelled and Ended, but the problem is that there is some sort of "lag", the cell gets the blue highlight but the label changes its color after a few milliseconds. I am not sure how to change that.

Here is a snippet of my code:

#import "AnnouncementCell.h"

@implementation AnnouncementCell
@synthesize date;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    // Initialization code
    date=[[UILabel alloc] initWithFrame:CGRectMake(220, 13, 100, 22)];
    date.textColor=[UIColor blueColor];
    date.font=[UIFont fontWithName:@"Helvetica" size:14.0];
    [self addSubview:date];
}
return self;
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
date.textColor=[UIColor whiteColor];
[super touchesBegan:touches withEvent:event];

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
date.textColor=[UIColor blueColor];    
[super touchesEnded:touches withEvent:event];

}

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
date.textColor=[UIColor blueColor];   
[super touchesCancelled:touches withEvent:event];

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

@end
John Topley
  • 113,588
  • 46
  • 195
  • 237
Cosmin
  • 2,840
  • 5
  • 32
  • 50

2 Answers2

0

You could try calling the date.textColor=[UIColor whiteColor]; in the didSelectRowAtIndexpath method of the UITableViewController, which i think is called before your own implemented methods.

user1242094
  • 107
  • 2
  • 10
0

you can use UIGestures in this situation:

for using this mechanism you need to alter code and may be need to make some tweakings.

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
 initWithTarget:self 
 action:@selector(tapDetected:)];
doubleTap.numberOfTapsRequired = 1;
[self addGestureRecognizer:doubleTap];
[doubleTap release];

-(void)tapDetected:(UIGestureRecognizer*) gesture {
self.lblTitle.backgroundColor=[UIColor blueColor];
[self setNeedsDisplay];
}

self = UITableViewCell.

also need to apply longTapGesture for the same. same thing working at my end.

Hope this will help you out.

Prabhat Kasera
  • 1,129
  • 11
  • 28