ios - 如何在 IOS 7 中删除第一行 UITableView 之前的间隙

标签 ios uitableview uiscrollview storyboard scrollview

在我的 UIViewController 中,我拖了一个 UITableView,它有 2 个自定义原型(prototype)单元格。基本上它是 Accordion 。 当我在上面加载数据时,我的表格 View 起始位置和第一行之间总是有间隙。当我向下滚动时它工作正常。我在谷歌中搜索并找到了一些建议,比如

 self.automaticallyAdjustsScrollViewInsets = YES;

在 viewDidLoad 中或在下面的代码中添加此代码

UIEdgeInsets insets = UIEdgeInsetsMake(self.topLayoutGuide.length,
                                       0.0,
                                       self.bottomLayoutGuide.length,
                                       0.0);
_detailsTableView.contentInset = insets;

 YouStoryboard.storyboard > YouViewController > Attributes inspector > Uncheck - Adjust scroll view insets

但是这些都不适合我。这是我的 UITableView 截图。请建议我如何删除标记为红色的间隙。

enter image description here

解决这个问题后 UITableView 应该是这样的

enter image description here

检查员图片 1

enter image description here

最佳答案

尝试实现这个方法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    CGFloat height = UITableViewAutomaticDimension;
    if (section == 0) {
        height = 0.5f;
    }
    return height;
}

这将删除第一节标题的间距。如果你想删除部分之间的所有间距,你总是可以返回 0.5f。需要这样一个奇数值是因为 Apple 不允许您在此方法中返回 0。 (这与根本不实现该方法具有相同的效果。)但值 0.5f 将具有预期的效果。

关于ios - 如何在 IOS 7 中删除第一行 UITableView 之前的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25284470/

相关文章:

ios - 停止导航栏重叠内容

iOS 增加 UITableViewCell 中 UIButton 的触摸区域

iphone - 将自定义对象的 NSArray 转换为带索引的按字母顺序划分的 UITableView?

ios - 以编程方式在 iOS 上滚动 UIWebView

iphone - 检查 scrollview.contentset 是否超过某个 x 值

ios - 无法本地化我的应用程序(添加本地化语言显示没有文件,也没有添加任何内容)

ios - 是否可以使用 Quartz 2D (CGrect) 进行捏合缩放?

ios - 在日志中定位自动布局约束错误

ios - 在具有动态高度的 UITableViewCell 原型(prototype)中拥有可变数量的 View 是否可行?

ios - 到达底部时删除底部的 ScrollView Gradient Fade