mrc下自定义UITableViewCell写法

本文介绍了一个自定义UITableViewCell类的实现方式,包括初始化方法与dealloc方法的重写,并演示了如何在UITableViewCell中添加UILabel来显示不同颜色的文字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#import <UIKit/UIKit.h>

@interface MyTableViewCell : UITableViewCell
@property(nonatomic,retain) UILabel *firstLabel;
@property(nonatomic,retain) UILabel *secondLabel;
@property(nonatomic,retain) UILabel *thirdLabel;
@end
#import "MyTableViewCell.h"

@implementation MyTableViewCell
-(void)dealloc{
//    self.firstLabel = nil;
//    self.secondLabel = nil;
//    self.thirdLabel = nil;

            ||
//    [self.firstLabel release];
//    [self.secondLabel release];
//    [self.thirdLabel release];
            ||
    [_firstLabel release],_firstLabel = nil;
    [_secondLabel release],_secondLabel = nil;
    [_thirdLabel release],_thirdLabel = nil;
    [super dealloc];
}
- (void)awakeFromNib {
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _firstLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 10, 10)];

        _firstLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_firstLabel];


        _secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 20, 10, 10)];
        _secondLabel.backgroundColor = [UIColor yellowColor];

        [self.contentView addSubview:_secondLabel];


        _thirdLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 30, 10, 10)];
        _thirdLabel.backgroundColor = [UIColor cyanColor];

        [self.contentView addSubview:_thirdLabel];
    }
    return self;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值