创建tableviewcell

来源:互联网 发布:mac硬盘格式化方案 编辑:程序博客网 时间:2024/05/16 06:12
创建tableviewcell 

1、在view文件夹中新建cell 的文件
2、在控制器的 cell 处 赋值建好的 cell 文件

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    HJMyMessageViewCell *cell = [HJMyMessageViewCell cellWithTableView:tableView];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;

}

3、在cell的头文件中 

+ (instancetype)cellWithTableView:(UITableView *)tableView;

4、在cell的实现文件中

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

    if(self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])

    {

        UIView *XXX。。。。

       在这里布局

        [self.contentView addSubview:XXX];

    }

    return self;

}


+ (instancetype)cellWithTableView:(UITableView *)tableView

{

    static NSString *ID = @"message";

    HJMyMessageViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    if (cell == nil) {

        cell = [[HJMyMessageViewCell allocinitWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

    }

    return cell;

}


5.子控件的frame写在 layout中

0 0
原创粉丝点击