我正在创建一个表格视图,其中有 10 个部分,所有部分都有标题视图,但没有单元格。所以,简而言之,我的表视图将仅显示 10 个标题视图;任何部分都不会有单元格。现在,当我这样做时,该部分的标题视图之间有一些空间。我想删除那个空格。那可能吗?您能为我提供一些提示或解决方法来实现这一目标吗?
以下是数据源方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 10;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel * label = [[UILabel alloc] init];
label.backgroundColor = [UIColor grayColor];
return label;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44.0f;
}
Here is the screenshot of the output:
![enter image description here](https://i.stack.imgur.com/MPsuR.png)
我这样做的原因有点复杂,我无法通过写作来解释。我想要做的就是在该部分的标题视图中没有间距。先感谢您。
尝试这个..
self.tableView.rowHeight = 0; // in viewdidload
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; // in viewdidload
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return <your header height>;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return <your header view>;
}
也将表分隔符设置为无。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)