0

我已经查看了网络,但没有找到适合我情况的答案。所以我有一个 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
4

2 回答 2

0

您可以尝试在 UITableViewControllerdate.textColor=[UIColor whiteColor];didSelectRowAtIndexpath方法中调用,我认为它是在您自己实现的方法之前调用的。

于 2012-05-21T12:10:40.427 回答
0

您可以在这种情况下使用 UIGestures:

要使用此机制,您需要更改代码并且可能需要进行一些调整。

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];
}

自我 = UITableViewCell。

也需要为相同的应用 longTapGesture。同样的事情在我的最后工作。

希望这会帮助你。

于 2012-05-21T15:02:12.153 回答