Ios UITableViewCellStyleSubtitle单元格的分隔线未采用全宽

Ios UITableViewCellStyleSubtitle单元格的分隔线未采用全宽,ios,xcode,uitableview,tableview,Ios,Xcode,Uitableview,Tableview,我已经为我在GitHub的问题做好了准备 当使用单元格类型(在Xcode Interface Builder中称为Subtitle)时,由于某些原因,水平线没有到达屏幕的左侧: 在上面的屏幕截图中,您可以看到“空单元格”中的分隔线正好占据了整个宽度 首先,我认为图标(大小:)不适合单元格,并试图增加行高,但这没有帮助 此外,我还尝试将自定义插入设置为自定义,并将左侧设置为0像素(表视图和MyCell都是如此),但左侧仍有一个间隙: 下面是我的源代码: 更新:这个答案的源代码最终帮助了我:

我已经为我在GitHub的问题做好了准备

当使用单元格类型(在Xcode Interface Builder中称为Subtitle)时,由于某些原因,水平线没有到达屏幕的左侧:

在上面的屏幕截图中,您可以看到“空单元格”中的分隔线正好占据了整个宽度

首先,我认为图标(大小:)不适合单元格,并试图增加行高,但这没有帮助

此外,我还尝试将自定义插入设置为自定义,并将左侧设置为0像素(表视图和MyCell都是如此),但左侧仍有一个间隙:

下面是我的源代码:

更新:这个答案的源代码最终帮助了我:


将表视图分隔符插入添加到零。不仅仅是表视图单元格

将此代码添加到
cellForRowAtIndexPath
中:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //....
    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=8.0)
    {
        cell.layoutMargins = UIEdgeInsetsZero;
        cell.preservesSuperviewLayoutMargins = NO;
    }
}
与代码的集成:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];

    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=8.0)
    {
        cell.layoutMargins = UIEdgeInsetsZero;
        cell.preservesSuperviewLayoutMargins = NO;
    }

    NSDictionary* item = [self.items objectAtIndex:indexPath.row];
    cell.textLabel.text = item[@"title"];
    cell.detailTextLabel.text = item[@"subtitle"];
    UIImage* icon = [UIImage imageNamed:item[@"icon"]];
    [cell.imageView setImage:icon];

    return cell;
}
请参见预览:


在iOS 8中,您必须添加一些代码才能做到这一点。检查答案亚历山大,好久不见!:)我能说服你不要这样做吗?为什么会有插图,为什么有图像时插图会改变,这有美学上的原因。好吧,让我们等待另一个答案@AlexanderFarberBrilliant!遗憾的是,围绕愚蠢的iOS行为开展工作并没有获得诺贝尔奖。当然,这个解决方案是有代价的:开发者可能有其他原因不想改变单元格的边距。但是有很多方法可以解决这个问题(添加一个子视图,它有自己的页边距)。在
cellforrowatinexpath:
设置三件事:(1)单元格的分隔符插入;(2) 单元格的布局边距;(3) 单元格的
保留PerViewLayoutMargins
。“那就行了。”阿什什卡卡德谢谢你的回答。但是,执行此操作后,会再次留下一些空间。有没有办法也包括这些?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //....
    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=8.0)
    {
        cell.layoutMargins = UIEdgeInsetsZero;
        cell.preservesSuperviewLayoutMargins = NO;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];

    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=8.0)
    {
        cell.layoutMargins = UIEdgeInsetsZero;
        cell.preservesSuperviewLayoutMargins = NO;
    }

    NSDictionary* item = [self.items objectAtIndex:indexPath.row];
    cell.textLabel.text = item[@"title"];
    cell.detailTextLabel.text = item[@"subtitle"];
    UIImage* icon = [UIImage imageNamed:item[@"icon"]];
    [cell.imageView setImage:icon];

    return cell;
}