IOS学习之——自定义的Cell (代码)

        //*****************************************************************************     04 自定义的 cell

        //目的是来显示消息的
        微博项目:
        步骤:1.创建一个CZMicroBlogCell  继承UITableViewCell
        2.导入头文件  #import "CZMicroBlogCell.h"//(在ViewController.m 中)
        3.接着写数据源的方法 // 具体操作参考  04-实现数据源的方法
        设置组//如果只有一组的话 就可以不用写这行代码   return 1;
        设置行
        设置cell  (1)//创建可重用的自定义cell
        CZMicroBlogCell *cell =[CZMicroBlogCell microBlogCellWithTableView:tableView];
        (2)//设置子控件的值
        CZMicroBlogCell *microBlog =self.microBlogs[indexPath.row];
        cell.microBlog =microBlog;//它应该提供一个模型属性3//返回
        return cell;
        // 因为没有 microBlog 属性 和microBlogCellWithTableView 类方法  所以我们要去写


        //(在ViewController.h 中)
        @class CZMicroBlog;
        @property(nonatomic,copy) CZMicroBlog *microBlog;
        +(instancetype)microBlogCellWithTableView:(UITableView *)tableView;

        //(在CZMicroBlogCell.m中)实现这个类方法

//        QQ项目
        //1 创建自定义可重用cell的对象
        + (instancetype)messageCellWithTableView:(UITableView *)tableView
        {
            static NSString *reuseId = @"msg";
            CZMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
            if (cell == nil) {
                cell = [[CZMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId];
            }
            return cell;
        }

        //2 创建子控件
        - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
        {
            if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
                //时间
                UILabel *timeView = [[UILabel alloc] init];
                [self.contentView addSubview:timeView];
                self.timeView = timeView;
                //头像
                UIImageView *iconView = [[UIImageView alloc] init];
                [self.contentView addSubview:iconView];
                self.iconView = iconView;
                //聊天内容
                UIButton *textView = [[UIButton alloc] init];
                [self.contentView addSubview:textView];
                self.textView = textView;

            }
            return self;
        }

        //3 重写属性的setter方法
        - (void)setMessage:(CZMessage *)message
        {
            _message = message;

        }
                @end
        //没办法算高度  所以要创建一个frame 模型
        类名字 CZMessageFrame   继承 NSObject

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值