UITableViewCell删除后缩进

时间:2016-02-20 15:15:19

标签: ios uitableview autolayout

出于某种原因,我在执行删除后在tableviewcell上得到缩进。

-(void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {

    HMFAlbum *album = [self albumsForListState][indexPath.row];

    if ([album.tracks containsObject:[[GVMusicPlayerController sharedInstance] nowPlayingItem]]) {
        [[GVMusicPlayerController sharedInstance] stop];
    }

    if ([[HMFDatabaseManager sharedManager] deleteDeviceAlbum:album]) {
        NSLog(@"Deleted Album");
        //remove album from originalArray
        NSMutableArray *modifiedDeviceAlbums = [NSMutableArray arrayWithArray:self.originalDeviceAlbumsArray];
        [modifiedDeviceAlbums removeObject:album];
        self.originalDeviceAlbumsArray = modifiedDeviceAlbums;
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    } else {
        NSLog(@"failed to delete Album");
        tableView.editing = false;
    }

}

这是一个前后截图。

enter image description here enter image description here

我已经尝试过这样做以消除问题但没有成功:(

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

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

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

    // Prevent the cell from inheriting the Table View's margin settings
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }

    // Explictly set your cell's layout margins
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }

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

}

编辑1:我了解到正在缩进的是单元格的内容视图。

1 个答案:

答案 0 :(得分:0)

我通过将其添加到单元格的子类来修复。

- (void)layoutSubviews {
    self.contentView.frame = self.bounds;
}