首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >减少UITableView各部分之间的空间

减少UITableView各部分之间的空间
EN

Stack Overflow用户
提问于 2010-05-12 17:03:58
回答 7查看 94.1K关注 0票数 144

有没有办法减少UITableView的两个部分之间的空间?在我的每个单独的部分之间大约有15个像素。我已经尝试为-tableView:heightForFooterInSection:-tableView:heightForHeaderInSection:返回0,但这不会改变任何事情。

有什么建议吗?

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2010-05-12 17:59:31

这有点棘手,但试一下下面的代码:

代码语言:javascript
复制
- (CGFloat)tableView:(UITableView*)tableView 
           heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 6.0;
    }

    return 1.0;
}

- (CGFloat)tableView:(UITableView*)tableView 
           heightForFooterInSection:(NSInteger)section {
    return 5.0;
}

- (UIView*)tableView:(UITableView*)tableView 
           viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (UIView*)tableView:(UITableView*)tableView 
           viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

相应地更改这些值。为了删除空格,我认为0.0不会被接受。最小的合理值似乎是1.0。

票数 267
EN

Stack Overflow用户

发布于 2011-09-12 22:04:43

对于所有想要将距离缩小到0的人,您必须使用:

代码语言:javascript
复制
tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;

因为UITableViewDelegate的服务只产生从大于零的浮点数开始的效果。

代码语言:javascript
复制
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1.0;
}


-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
    return 1.0;
}

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}

(在XCode 4.0.2中使用iOS 4.1 )

票数 142
EN

Stack Overflow用户

发布于 2011-01-27 11:27:45

实际上,您可以在Interface Builder的size选项卡下设置页脚/页眉/单元格的高度。默认情况下,页眉/页脚设置为10.0。

票数 33
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2817308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档