简单的自定义cell

创建类继承于UITableViewCell(带有xib)
如图:图片UIImage 文字 UIlabel
在这里插入图片描述
在ViewController.m界面导入头文件
#import “onTableViewCell.h”
接下来是ViewDidLoad

@interface ViewController ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong )UITableView *tbv;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tbv];
}
-(UITableView *)tbv{
    if (!_tbv) {
        _tbv = [[UITableView alloc]initWithFrame:self.view.frame];
        _tbv.dataSource  =self;
        _tbv.delegate = self;
        [self.tbv registerNib:[UINib nibWithNibName:@"onTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    }
    return _tbv;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 8;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    onTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    _tbv.rowHeight = 100;
    return cell;
}

运行效果图:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Py88888/article/details/83057727