私の推奨はシングルトンになります。例えば:
@interface ColorThemeSingleton : NSObject
@property (strong, atomic) UIColor *tableViewBackgroundColor;
+(ColorThemeSingleton *)sharedInstance;
@end
と.m
:
#import "ColorThemeSingleton.h"
@implementation ColorThemeSingleton
@synthesize tableViewBackgroundColor = _tableViewBackgroundColor;
+(ColorThemeSingleton *)sharedInstance{
static ColorThemeSingleton *shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared = [[ColorThemeSingleton alloc] init];
});
return shared;
}
-(id)init{
if ((self = [super init])){
_tableViewBackgroundColor = [UIColor whiteColor]; // Default color
}
return self;
}
@end
それからちょうどtableView:cellForRowAtIndexPath:
でif(cell==nil){}
後、あなたが追加します。
cell.backgroundColor = [ColorThemeSingleton sharedInstance].tableViewBackgroundColor;
そして、あなたがウェブ、セットからあなたの色をロードします取得されたカラーに対するプロパティの値次にセルがtableView:cellForRowAtIndexPath:
を通過するとき、その色は新しい色になります。
基本的にはtableView
のdataSource
に#import""
とcell.backgroundColor =
を追加してください。私には、すべてのコントローラーでUITableViewCell
のクラスを変更するよりもはるかに優れています。