问题
I am trying to have custom TableViewCell with initWithStyle, since it says initWithFrame is deprecated after 3.0. Everything worked fine with initWithFrame before.
Is there any tutorials or sample code available for this? Thanks.
回答1:
I have subclassed UITableViewCell then override the initWithStyle method.
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
// Initialization code
msgText = [[UILabel alloc] init];
[self.contentView addSubview:msgText];
}
return self;
}
msgText is a UILabel property of the class and I set the text property of the label elsewhere. You can add any views to self.contentView you like. I also set the frame of each of the subviews when I add the content like text and/or images.
来源:https://stackoverflow.com/questions/1754036/how-to-make-custom-tableviewcell-with-initwithstyle-after-3-0