如何阻止单元格缩进-shouldIndentWhileEditingRowAtIndexPath不起作用 [英] How to stop cells from indenting - shouldIndentWhileEditingRowAtIndexPath has no effect

查看:301
本文介绍了如何阻止单元格缩进-shouldIndentWhileEditingRowAtIndexPath不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义单元格的普通(未分组)tableView,当我单击编辑"按钮时,单元格缩进了.我不希望那样,我希望删除符号位于我的单元格的正上方.

I have a plain (not grouped) tableView with custom cells, and when I hit the Edit button, the cells indent. I don't want that, I want the deletion sign to lay right on top of my cell.

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

I tried shouldIndentWhileEditingRowAtIndexPath and also cell.shouldIndentWhileEditin = NO; as well as cell.indentionLevel = -3, but both won't have any effect. Any idea why?

这可能是由于我的设置吗?我遵循了本教程,并且我还尝试了类似

Could this be due to my setup? I followed this tutorial, and I also tried a setup like Davyd suggested here, but the last did not only still indent my cells, it made it even worse, as the cells were indented, when I press Done.. and I can't get the background image to cover the whole cell...

那么,有谁知道如何阻止纯表视图中的自定义单元格的意图,同时仍然显示出删除和移动符号?

So, anyone knows how to stop custom cells in a plain tableview from intending, while still showing the delete and move sign?

// 顺便说一句,我在IB中构建自定义单元.我可以取消勾选标记在编辑时缩进",这无关紧要.我可以更改缩进级别和宽度的值,没有效果.如果我更改了编辑附件,它会愉快地显示它. 希望对您有帮助.

// btw, I build the custom cell in IB. I can take away the checkmark saying "Indent while Editing", it doesn't care. I can change the values for indention level and width, no effect. If i change the editing accessory, it happily displays it. Hope that helps..

谢谢!

推荐答案

经过大量研究并逐像素尝试,结果证明,我需要使用-(void)layoutSubviews从原始状态过渡"到原始状态size ..如果有人需要这样做,这是我的代码,放在我的CustomCell.m中:

After a lot of research and trying pixel by pixel, it turned out, I needed to use -(void)layoutSubviews to "transit" from the original state to the original size.. If someone else ever needs to do that, here's my code, placed in my 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;
        }
    }
}

希望有帮助:)

这篇关于如何阻止单元格缩进-shouldIndentWhileEditingRowAtIndexPath不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆