iphone - 分隔线之前的空白进入我的 TableView

标签 iphone ios uitableview interface-builder

我有一个关于 UITableView 的问题... 我有一个 UITableViewController 并创建了一个自定义单元格。 当我可视化 tableView 时,我看到分隔线之前有一点空白,您可以在这个屏幕截图中看到:

enter image description here

为什么?这是默认可视化? 我可以改变一些东西来删除这个白色的左填充吗?

最佳答案

iOS 7 默认提供前导空格,即使是自定义单元格也是如此。

检查 UITableviewCell 的此属性 separatorInset 以删除/添加单元格行分隔符两端的白色间距。

//去除空白

cell.separatorInset = UIEdgeInsetsZero;

或者,在 UITableView 级别,您可以使用此属性 -

if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {  // Safety check for below iOS 7 
    [tableView setSeparatorInset:UIEdgeInsetsZero];
}

更新 - 以下代码适用于 iOS 7 和 iOS 8:

-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

关于iphone - 分隔线之前的空白进入我的 TableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19499366/

相关文章:

iphone - 如何拆分 iOS 3.0 和 iOS 3.2 的代码,以便我可以使用 MPMoviePlayerViewController(如果 OS 3.2++)

iphone - 存储省份、城市并与 plist 协调

iphone - 核心数据: sorting by count in a to-many relationship

iphone - 如何检测用户在iphone sdk中绘制矩形、椭圆形或其他几何图形?

ios - EXC_BAD_INSTRUCTION 尝试从 Parse 获取图像时

ios - ld : library not found for -lgcc_s. 10.5 Xcode

ios - 无法在 IOS 模拟器上运行 React Native 项目

iphone - 从 UITableViewCell 中的详细信息公开按钮显示 UIPopoverController

ios - 如何去除圆形矩形贝塞尔曲线路径的角点

iphone - 以编程方式更改 View 尺寸时,Autolayout 似乎不起作用