xib 方式
1.在Cell.h文件中加一个宏
#define cellIdentifier @"customCell"
2. ViewController中:
- (void)viewDidLoad {
[super viewDidLoad];
[_tableView registerNib:[UINib nibWithNibName:cellIdentifierbundle:nil] forCellReuseIdentifier:cellIdentifier];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
return:cell
}
StoryBoard方式
1.在Cell.h文件中加一个宏
#define cellIdentifier @"customCell"
备注:IB中Identifier 也要填 customCell
2.ViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier forIndexPath:indexPath];
return cell;
}