- (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;
}
}
}