美文网首页UIKitiOS开发常用知识点
UITableViewStyleGrouped模式下烦人的多余间

UITableViewStyleGrouped模式下烦人的多余间

作者: yanhooIT | 来源:发表于2016-12-21 14:57 被阅读5646次

第一个section上边多余间距处理

// 隐藏UITableViewStyleGrouped上边多余的间隔
_tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];

每个section下边多余间距处理

// 隐藏UITableViewStyleGrouped下边多余的间隔
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}
  • 备注:若传入的 height == 0,则 height 被设置成默认值
  • 若 height 小于屏幕半像素对应的高度,则不会被渲染,所以这里返回CGFLOAT_MIN,其实返回0.01也是可以的

补充:代码顺序的不同导致第一个section上边出现多余间距

  • 在设置代理设置tableFooterView,上边会出现多余间距
tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
tableView.tableFooterView = [UIView new];
tableView.delegate = self;
tableView.dataSource = self;
  • 在设置代理设置tableFooterView,上边不会出现多余间距
tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
tableView.delegate = self;
tableView.dataSource = self;
tableView.tableFooterView = [UIView new];
  • 可以通过第一个section上边多余间距处理的办法来解决因代码顺序导致的上述问题,所以这里建议要解决第一个section上边多余间距还是通过文章开头所说的解决办法更好

参考文章

相关文章

网友评论

本文标题:UITableViewStyleGrouped模式下烦人的多余间

本文链接:https://www.haomeiwen.com/subject/pteqvttx.html