如何阻止单元格缩进 - shouldIndentWhileEditingRowAtIndexPath无效

Nar*_*lle 2 iphone objective-c uitableview custom-cell

我有一个带有自定义单元格的普通(未分组)tableView,当我点击"编辑"按钮时,单元格缩进.我不希望这样,我希望删除标志位于我的单元格顶部.

我试过了shouldIndentWhileEditingRowAtIndexPath以及cell.shouldIndentWhileEditin = NO; 以及cell.indentionLevel = -3,但两者都没有任何效果.知道为什么吗?

这可能是由于我的设置?我按照这个教程,我也尝试了像戴维德这样建议的设置,但最后一次不仅使我的细胞缩进,它更糟糕,因为细胞缩进,当我按完成时...我不能得到背景图像覆盖整个细胞......

那么,任何人都知道如何停止普通桌面视图中的自定义单元格,同时仍然显示删除和移动标志?

//编辑:顺便说一句,我在IB中构建自定义单元格.我可以拿走"编辑时缩进"的复选标记,它并不关心.我可以改变压痕水平和宽度的值,没有效果.如果我更改编辑附件,它会愉快地显示它.希望有所帮助..

谢谢!

Nar*_*lle 5

经过大量的研究并逐个像素地尝试,事实证明,我需要使用-(void)layoutSubviews从原始状态"转换"到原始大小.如果其他人需要这样做,这里是我的代码,放在我的CustomCell中.M:

- (void)willTransitionToState:(UITableViewCellStateMask)aState
{
[super willTransitionToState:aState];
self.state = aState;
}


- (void)layoutSubviews
{
[super layoutSubviews];
// no indent in edit mode
self.contentView.frame = CGRectMake(0,                                          
                                    self.contentView.frame.origin.y,
                                    self.contentView.frame.size.width, 
                                    self.contentView.frame.size.height);

if (self.editing )        
{
    NSLog(@"subview");
    float indentPoints = self.indentationLevel * self.indentationWidth;

    switch (state) {
        case 3:
            self.contentView.frame = CGRectMake(indentPoints,
                                                self.contentView.frame.origin.y,
                                                self.contentView.frame.size.width +124,// - indentPoints, 
                                                self.contentView.frame.size.height);   

            break;
        case 2:
            // swipe action
            self.contentView.frame = CGRectMake(indentPoints,
                                                self.contentView.frame.origin.y,
                                                self.contentView.frame.size.width +75,// - indentPoints, 
                                                self.contentView.frame.size.height);   

            break;
        default:
            // state == 1, hit edit button
            self.contentView.frame = CGRectMake(indentPoints,
                                                self.contentView.frame.origin.y,
                                                self.contentView.frame.size.width +80,// - indentPoints, 
                                                self.contentView.frame.size.height);  
            break;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

希望有帮助:)