0

カスタムの 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];
}
}
4

1 に答える 1

0

次の解決策で修正できました

#import "CustomTableViewCell.h"

@implementation CustomTableViewCell{
    UIView *backgroundView;
    UIView *visibleBackgroundView;
}

- (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)];
    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;
    [self setSelectionStyle:UITableViewCellSelectionStyleNone];


    }
    return self;
}

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

// Configure the view for the selected state
if (selected) {

}
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
    [visibleBackgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"selectedTableViewCell.png"]]];
} else{
     [visibleBackgroundView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"tableViewCell.png"]]];
}
}
于 2013-02-23T03:34:54.383 に答える