当它处于编辑模式时,我想在我的表视图中添加一个节标题。基本上我只是希望它成为数据源的一部分,以与表的其余部分具有相同的外观(请参阅下图以获得所需的结果)。但是在数据源中插入一个对象(“添加联系人”)会导致在从编辑模式切换进出时进行大量的微观管理,它实际上不是数据源的一部分,它更像是一个标题。
我尝试使用以下代码片段来实现相同的效果,但结果并不正确(只是将添加联系人文本添加到该部分的顶部,但不是作为分组表格单元格的一部分)。
有人对我缺少什么有任何线索吗?
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
if (section == 1) {
UITableViewCell *addContactCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
addContactCell.textLabel.text = @"Add Contact";
addContactCell.textLabel.opaque = NO;
return addContactCell;
} else {
return nil;
}
}