I have a simple Custom UITableViewCell in my project, and just added an Edit action to the table. Everything seems fine, but indentation is not working when editing, and edit Icons overlap the content. (Not to mention the delete button)

The custom cell is created in interface builder, with the standard constraints as usual and I have already tried to ovverride the layoutSubviews method in the class, as mentioned in other places with no luck as follows;

I have also confirmed that the subviews are in fact within the contentView and everything seems fine in the View and Code.

Cell also has indentationLevel/Width set up programatically and autoresize masks to automatic width.

As a last resort I could create the UITableViewCell programatically, but don't think it could help.

As per recommended, I have also made sure the Constraints on the Cell content to be fixed to the superview.

Also manually set de autoResizingMasks in Code with no luck

--
Edit:

I have set the Background color of the contentView to black manually, and found that it is indenting correctly on edit mode, even without overriding the "layoutSubviews". In fact, it works better that with it.

However, as you can see, the contents are not getting indented. Initially I tought the contents of the cell (UIImage) were not subviews of the contentView, but nslogging the subviews, show that they are.

4 Answers
4

Indentation isn't the same as adjusting the content view when entering edit mode.

You're right, this seems simple and usually works almost straight out of the box. Typically the only things you need to change are the autoresizing masks of the components you add to the cell. Content on the left should have a fixed left margin, content on the right should have a fixed right margin.

When the cell enters editing mode the content view's size is adjusted to allow room for the editing accessories. If your content has these resizing masks, it will move along with this. Your layoutSubviews method above is quite likely undoing all this by setting the content view back to full width because you are using indentation incorrectly - though I can't be sure of that from the information in the question.

UPDATE

This is a issue (bug?) with constraints in UITableViewCells. You can go back to autoresizing masks by selecting the "File" tab in the storyboard / interface builder screen (if you want to use constraints elsewhere, use a standalone nib for the cell) and unchecking "Use Autolayout":

I have removed the lauoutSubview override and changed the content margins to be fixed in Interface Builder. See: link but still indentation is not working when entering edit mode. Any other idea?
– afterxleepOct 11 '12 at 18:32

Ahh, I didn't realise you were using constraints. I haven't used them in anger yet. I'll have a think.
– jrturtonOct 11 '12 at 19:12

1

Looks like this question has the answer you're looking for, though I can't believe it's that hard!
– jrturtonOct 11 '12 at 19:23

I've been trying everything possible to avoid doing all that, as it seems absurd, for solving such a simple problem. I'm about to try anyway in desperation.
– afterxleepOct 11 '12 at 20:13