Моя рекомендация будет синглтон.например:
@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
Затем сразу после if(cell==nil){}
in tableView:cellForRowAtIndexPath:
вы добавите:
cell.backgroundColor = [ColorThemeSingleton sharedInstance].tableViewBackgroundColor;
И когда вы загружаете свой цвет из Интернета, установите значение свойства для выбранного цвета.В следующий раз, когда ячейка пройдет через tableView:cellForRowAtIndexPath:
, цвет будет новым.
Поэтому просто добавьте #import""
и cell.backgroundColor =
к tableView
dataSource
.Для меня это намного лучше, чем менять класс UITableViewCell
на каждом контроллере.