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