我想在初始化我的自定义 UITableViewCell(来自 xib 文件)时动态地更改一些东西(隐藏 UITextView,更改字体颜色),但不调用 initWithStyle 选择器。
我的代码如下:
目标表单元格.h
@interface GoalTableCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *fixedText;
@property (strong, nonatomic) IBOutlet UITextView *editableText;
@property (strong, nonatomic) IBOutlet UIImageView *imageCircle;
@end
目标表单元格.m
@implementation GoalTableCell
- (void) setup
{
self.editableText.hidden = TRUE;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if( self = [super initWithStyle:style reuseIdentifier:reuseIdentifier] ) {
[self setup];
}
return self;
}
@end
最佳答案
当从 NIB 文件中取消归档任何实例时,'initWithCoder: method will be called because the archived properties are provided to the instance via the
解码器参数。
从 NIB 加载实例时,awakeFromNib
方法也被调用。
initWithCoder: is called to create the instance.
awakeFromNib` 在实例从 NIB 完全取消归档(连接导出)后被调用。
关于ios - 覆盖从 xib 文件初始化的 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17664888/