0
我想在處於編輯模式時向我的tableview添加分段標題。基本上,我只是希望它成爲數據源的一部分,與表格的其餘部分具有相同的外觀(請參閱下圖查看所需結果)。但是,在數據源中插入一個對象(「添加聯繫人」)會導致在進入編輯模式和從編輯模式切換時引發大量微觀管理,而實際上它不是數據源的一部分,而更像是標題。iOS - UITableView分組表的表頭部分
我嘗試使用下面的代碼片段來實現相同的效果,但它沒有變成正確的(只是添加了添加聯繫人文本來坐在部分的頂部,但不是作爲分組表格單元的一部分) 。
任何人有任何我失蹤的線索嗎?
- (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;
}
}