Por que o initWithCoder não está inicializando itens corretamente?
Eu tenho uma subclasse deUITableViewCell
. Minha subclasse contém váriosUILabel
s. Eu quero que minha subclasse inicialize esses rótulos para algumas configurações padrão que se aplicam a todas as células de visualização de tabela minhas.
Eu li que eu deveria estar usandoinitWithCoder
por esta. MinhasinitWithCoder
função está sendo chamada, e eu posso percorrer cada linha na minha função e parece passar pelos movimentos. Quando executo meu aplicativo, não vejo nenhuma das propriedades sendo aplicadas. Mais notavelmente, a fonte não está sendo alterada. Eu não acho que nenhuma das propriedades que estou modificando na minhaUILabel
s estão realmente sendo salvos ou exibidos.
Eu estou usando esta subclasse em conjunto com umStoryboard
. Eu sei que minhas alterações não serão refletidas noStoryboard
, mas eles também não estão sendo refletidos quando o aplicativo é executado - apesar do meu código ser executado.
Edit: Eu queria mencionar isso antes de tentar substituirinitWithCoder
, Eu tinha um método de instância nessas subclasses em que eu executava essa lógica. Eu apenas chamava esse método de instância dentro decellForRowAtIndexPath
. Este método estava funcionando, mas achei que seria útil ter essa lógica nesta subclasse ocorrendo automaticamente.
Alguma ideia? Meu código está abaixo:
#import "ThreadListCell.h"
@implementation ThreadListCell
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
// adjust the font settings of the title
self.title.font = [UIFont fontWithName:@"SourceSansPro-Black" size:16];
self.title.textColor = [UIColor colorWithWhite:0.267f alpha:1.0f];
// adjust the font settings of the subtitle
self.text.font = [UIFont fontWithName:@"SourceSansPro-Light" size:14];
self.text.textColor = [UIColor colorWithWhite:0.267f alpha:0.9f];
self.text.textColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
// adjust the font settings of the location
self.location.font = [UIFont fontWithName:@"SourceSansPro-Light" size:8];
self.location.textColor = [UIColor colorWithWhite:0.267f alpha:0.9f];
// adjust the UILabel settings of the title
self.title.numberOfLines = 0;
self.title.lineBreakMode = UILineBreakModeTailTruncation;
// adjust the UILabel settings of the subtitle
self.text.numberOfLines = 0;
self.text.lineBreakMode = UILineBreakModeTailTruncation;
// adjust the UILabel settings of the location
self.location.numberOfLines = 0;
self.location.lineBreakMode = UILineBreakModeTailTruncation;
self.location.textAlignment = UITextAlignmentRight;
}
return self;
}
@end
E o cabeçalho:
#import <UIKit/UIKit.h>
@interface ThreadListCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *text;
@property (nonatomic, weak) IBOutlet UILabel *title;
@property (nonatomic, weak) IBOutlet UILabel *location;
@end