如何在3.0之后使用initWithStyle制作自定义TableViewCell [英] How to make custom TableViewCell with initWithStyle after 3.0

查看:61
本文介绍了如何在3.0之后使用initWithStyle制作自定义TableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用具有initWithStyle的自定义TableViewCell,因为它说initWithFrame在3.0之后不推荐使用.之前initWithFrame都可以正常工作.

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.

推荐答案

我对UITableViewCell进行了子类化,然后重写了initWithStyle方法.

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是该类的UILabel属性,我在其他地方设置了标签的text属性.您可以将任何视图添加到所需的self.contentView中.添加诸如文本和/或图像之类的内容时,我还设置了每个子视图的框架.

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.

这篇关于如何在3.0之后使用initWithStyle制作自定义TableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆