1

これはちょっと変わった問題です!UIAppearance API を使用して UITableViewCells のスタイルを設定しています。次のコードを使用して、UITableViewCell のスタイルを設定します。

// table cell
    id tableCellAppearance = [UITableViewCell appearance];
    [tableCellAppearance setBackgroundView:[theme imageViewForTableViewCellBackground]];

// table cell
-(UIImageView *) imageViewForTableViewCellBackground
{
    UIImageView *backgroundView = [[UIImageView alloc] init];
    [backgroundView setImage:[UIImage imageNamed:@"tile_heading_background"]];

    return backgroundView;
}

アプリを実行して UITableViewCells を見ると、UITableView でスタイル設定されているセルは 1 つだけです。真ん中のセル。何故ですか?

4

1 に答える 1

2

プロトコルを作成しCustomUITableViewCellて実装する<UIAppearance>

CustomCell.h

@interface CustomCell : UITableViewCell <UIAppearance>

@property (nonatomic, weak) UIColor *backgroundCellColor UI_APPEARANCE_SELECTOR;

CustomCell.m

@implementation CustomCell

@synthesize backgroundCellColor;

-(void)setBackgroundCellColor:(UIColor *)backgroundColor
{
    [super setBackgroundColor:backgroundColor];
}

最後にビューでCustomCellを使用し、背景または画像を設定します

[[CustomCell appearance] setBackgroundCellColor:[UIColor redColor]];
于 2013-03-06T21:28:18.187 に答える