- (
void
)viewDidLoad {
[ super viewDidLoad ];
// 注册 cell
// 如果使用 Xib 文件加载 cell 的话 一定要注册
// 填写 Xib 的名字 不包含拓展名
// bundle 目录填工程目录 填写 nil 也可以找到
[ self . tableView registerNib :[ UINib nibWithNibName : @"TableViewCell1" bundle :[ NSBundle mainBundle ]] forCellReuseIdentifier : @"cell1" ];
[ super viewDidLoad ];
// 注册 cell
// 如果使用 Xib 文件加载 cell 的话 一定要注册
// 填写 Xib 的名字 不包含拓展名
// bundle 目录填工程目录 填写 nil 也可以找到
[ self . tableView registerNib :[ UINib nibWithNibName : @"TableViewCell1" bundle :[ NSBundle mainBundle ]] forCellReuseIdentifier : @"cell1" ];
- (
UITableViewCell
*)tableView:(
UITableView
*)tableView cellForRowAtIndexPath:(
NSIndexPath
*)indexPath {
/**
* 拖自定义 cell 的步骤
1. 创建实体类 关联 cell 类
2. 给 cell 添加 identifiter
3. 把 cell 上的空间拖成属性
4. 返回 cell 的方法上 更改自定义 cell 的类名
注意 : 两个 identifiter 一定要写一致
*/
if (indexPath. row % 2 == 0 ) {
TableViewCell1 *cell = [tableView dequeueReusableCellWithIdentifier : @"cell1" forIndexPath :indexPath];
cell. label1 . text = @"haha" ;
cell. label2 . text = @"he" ;
return cell;
} else {
TableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier : @"cell2" forIndexPath :indexPath];
cell. label1 . text = @"heng" ;
return cell;
/**
* 拖自定义 cell 的步骤
1. 创建实体类 关联 cell 类
2. 给 cell 添加 identifiter
3. 把 cell 上的空间拖成属性
4. 返回 cell 的方法上 更改自定义 cell 的类名
注意 : 两个 identifiter 一定要写一致
*/
if (indexPath. row % 2 == 0 ) {
TableViewCell1 *cell = [tableView dequeueReusableCellWithIdentifier : @"cell1" forIndexPath :indexPath];
cell. label1 . text = @"haha" ;
cell. label2 . text = @"he" ;
return cell;
} else {
TableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier : @"cell2" forIndexPath :indexPath];
cell. label1 . text = @"heng" ;
return cell;
}
}
}