I am trying to clear my code and use the principles of MVC by clicking on as many viewing-related materials as I can in the storyboard, as well as on custom UIView classes (i.e. instead of doing things related to viewing on UIViewController)
So, I have a custom UITableViewCell (called CustomCell) that has several properties, one of which is my own label. Since I load a cell from the storyboard, I initialize it initWithCoder, and not initWithStyle:reuseIdentifier:, this is what I have in CustomCell.m, which is a subclass UITableViewCell(for some reason I could not figure out how to set a custom font using the storyboard .. but this does not apply to this question):
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
NSLog(@"customizing cell font having text %@", self.label.text);
UIFont *customFont = [UIFont fontWithName:@"Montserrat" size:16];
self.label.textColor = [UIColor redColor];
[self.label setFont:customFont];
}
return self;
}
. null , b/c . self.label ( , , nib ), .. .
, , TableViewController:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
UIFont *customFont = [UIFont fontWithName:@"Montserrat" size:16];
[((CustomCell *)cell).label setFont:customFont];
}
. , , CustomCell.m
update:, . UITableViewCell initWithCoder, ! :
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor blueColor]];
[self setSelectedBackgroundView:bgColorView];
}
return self;
}
.