質問

I have a problem with my custom cells.
My cell is structured like this image:
enter image description here

Gray view = cell.contentView
Orange view = a button added as a subview to the contentView
Yellow view = a label added as subview to the contentView
Blue view = an image view added as subview to the contentView
Green view = accessory view

The problem is that when I toggle edit to tableView, my cell indents hiding accessory view and moving right everything else. I want to avoid this.
When I toggle editing mode, my cell mustn't move its content, the editing control (minus red button on the left) must take the place of the button inside the contentView and this last one should hide itself.

I tried tableView:shouldIndentWhileEditingRowAtIndexPath: method without success because my tableView is plain. I also tried to override willTransitionToState: method but I don't know how to do what I want.

Can someone help me?
Thank you so much!

役に立ちましたか?

解決

How have you added the subviews to the cell? If you add them directly to the cell instead of adding them to the content view, they won't get moved. It is the content view that is resized when the cell transitions to editing mode.

If you want to hide certain subviews, you should override setEditing:animated: in the cell subclass and hide / show as appropriate.

You may also need to add your subviews such that they are below the contentView in the view hierarchy, or bring the content view to the top after you have finished, using the bringSubviewToFront: method.

他のヒント

If you really don’t want the cell to resize, you could implement -layoutSubviews thusly:

-(void)layoutSubviews
{
    if ([self isEditing] == NO) {
        // Lay out subviews normally.
    }
}

When you go into edit mode, -layoutSubviews won’t follow the code path that lays out your views. This is assuming you’ve subclassed UITableViewCell.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top