我创建了一个自定义 tableviewcell 类,并且单元格加载完美,但是,当我单击它们时,它们消失并在我单击另一个单元格时返回。谁能帮我理解为什么?提前致谢!
#import "CustomTableViewCell.h"
@implementation CustomTableViewCell
UIView *backgroundView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 65)];
UIView *visibleBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(29, 0, backgroundView.bounds.size.width -58, backgroundView.bounds.size.height)];
[visibleBackgroundView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"tableViewCell.png"]]];
[backgroundView addSubview:visibleBackgroundView];
self.backgroundView = backgroundView;
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
if (selected) {
UIView *selectedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 65)];
UIView *visibleSelectedBackground = [[UIView alloc] initWithFrame:CGRectMake(29, 0, backgroundView.bounds.size.width -58, backgroundView.bounds.size.height)];
[visibleSelectedBackground setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"selectedTableViewCell@2x.png"]]];
[selectedBackgroundView addSubview:visibleSelectedBackground];
self.selectedBackgroundView = selectedBackgroundView;
}
}
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
[self setHighlighted:NO];
}
}