// 设置分割线:距离两边间距10
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setLayoutMargins:UIEdgeInsetsMake(0, 10, 0, 10)];
[cell setSeparatorInset:UIEdgeInsetsMake(0,10, 0, 10)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return 0.00001; // 把header高度设置很小,可以看成header的高度等于0
}
return 20;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
// 如果设置了section的header高度,不设置footer高度,footer默认等于header高度
return 0.00001; // 把footer高度设置很小,可以看成footer的高度等于0
}
// UITableView的style为UITableViewStyleGrouped
- (UITableView *)tableView
{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ICAN_WIDTH, ICAN_HEIGHT - ICAN_NAV_BAR_HEIGHT) style:UITableViewStyleGrouped];
_tableView.rowHeight = 50;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [[UIView alloc] init];
_tableView.layoutMargins = UIEdgeInsetsMake(0, 10, 0, 10);
_tableView.separatorInset = UIEdgeInsetsMake(0, 10, 0, 10);
}
return _tableView;
}
UITableView去掉Grouped样式的第一组Header组头
最新推荐文章于 2025-11-14 13:55:23 发布
本文介绍如何在 iOS 开发中使用 UITableView 的 Grouped 风格进行自定义布局,包括调整单元格间距、设置 section 的 header 和 footer 高度等细节。
3753

被折叠的 条评论
为什么被折叠?



