내 추천은 싱글 톤이 될 것입니다.
@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:
까지 실행되면 색이 새 색이됩니다.
기본적으로 과 cell.backgroundColor =
을 tableView
의 dataSource
에 추가하면됩니다. 모든 컨트롤러에서 UITableViewCell
의 클래스를 변경하는 것보다 훨씬 좋습니다.