创建类继承于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;
}
运行效果图: