简体   繁体   English

如何在3.0之后使用initWithStyle制作自定义TableViewCell

[英]How to make custom TableViewCell with initWithStyle after 3.0

I am trying to have custom TableViewCell with initWithStyle, since it says initWithFrame is deprecated after 3.0. 我试图使用initWithStyle自定义TableViewCell,因为它表示在3.0之后不推荐使用initWithFrame。 Everything worked fine with initWithFrame before. 以前使用initWithFrame一切正常。

Is there any tutorials or sample code available for this? 有没有可用的教程或示例代码? Thanks. 谢谢。

I have subclassed UITableViewCell then override the initWithStyle method. 我已经将UITableViewCell子类化,然后覆盖initWithStyle方法。

- (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. msgText是类的UILabel属性,我在其他地方设置标签的text属性。 You can add any views to self.contentView you like. 您可以将任何视图添加到您喜欢的self.contentView。 I also set the frame of each of the subviews when I add the content like text and/or images. 当我添加文本和/或图像等内容时,我还设置了每个子视图的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM