Font and textColor are gone - another UITableViewCell awakeFromNib

I don't know if this is specific to UITableViewCells , but rather common to UIViews (as I believe), but I noticed a problem with the cell.

As already mentioned, I have a custom subclass of UITableViewCell that loads from xib when it is initialized with the assigned init:

 - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:nil options:nil]; self = nib[0]; if (self) { // Initialization code _reuseIdentifier = reuseIdentifier; } return self; } 

It has UILabel as an output, and I set some of its properties in the awakeFromNib method:

 - (void)awakeFromNib{ [super awakeFromNib]; self.labelLeft.textColor = [UIColor grayColor]; self.labelLeft.font = [UIFont boldSystemFontOfSize:15.0f]; } 

The fact is that the shortcut does not save the textColor or font, and I do not understand why.
awakeFromNib is called and the output is connected correctly, since I can set the text.

I can get it to work with the settings for these properties after I set its text to a UITableViewDataSource , but I do not think it is correct, and I want to understand why this does not work.

Question :
Why doesn't it save the font and text and what can I do to make it work correctly?

+4
source share
2 answers

I have the same problem with all my shortcuts downloaded from .Nib . Then I discovered that the problem was in UIAppearance . I have the following line in AppDelegate :

 + (void)styleApplication { [[UILabel appearance] setFont:[MGStylesheet defaultLightFontOfSize:17]]; } 

This method updates all the fonts in my application and everything works fine until I start loading UIView from .Nib . When I remove this, everything will start to work as expected.

+2
source

Set label attributes in the nib file. If you divide the configuration of the interface into different places, this will lead to a simple start.

If you do not want to do this, move the label configuration to viewDidLoad:

-1
source

All Articles