为了账号安全,请及时绑定邮箱和手机立即绑定

减少UITableView部分之间的空间

减少UITableView部分之间的空间

守着一只汪 2019-12-13 09:50:03
有没有办法减少UITableView的两个部分之间的空间?我拥有的每个部分之间大约有15个像素。我确实已经尝试过为返回0 -tableView:heightForFooterInSection:,-tableView:heightForHeaderInSection:但这并没有改变任何东西。有什么建议么?
查看完整描述

3 回答

?
撒科打诨

TA贡献1934条经验 获得超2个赞

这有点棘手,但是请尝试以下代码:


- (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。


查看完整回答
反对 回复 2019-12-13
?
POPMUISE

TA贡献1765条经验 获得超5个赞

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


tableView.sectionHeaderHeight = 0.0;

tableView.sectionFooterHeight = 0.0;

因为提供UITableViewDelegate只会从大于零的浮点数开始产生效果。


-(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];

}

(将iOS 4.1与XCode 4.0.2结合使用)


查看完整回答
反对 回复 2019-12-13
?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

您必须减少节的页眉/页脚高度。然后,节之间的空间将减小。


试试这个代码


这个对我有用 :-)


tableView.sectionHeaderHeight = 2.0;

tableView.sectionFooterHeight = 2.0;


查看完整回答
反对 回复 2019-12-13
  • 3 回答
  • 0 关注
  • 571 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信