我已经查看了网络,但没有找到适合我情况的答案。所以我有一个 UITableCellView 的子类(我尝试做一个与电子邮件应用程序中的单元格非常相似的单元格)。我在右侧添加了一个标签,我想在其中使用蓝色显示日期。现在,当我触摸单元格时,我想更改标签的颜色,因为蓝色突出显示会隐藏它。我已经实现了 thouchesBegan、Canceled 和 Ended,但问题是存在某种“滞后”,单元格获得蓝色突出显示,但标签在几毫秒后改变其颜色。我不知道如何改变它。
这是我的代码片段:
#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