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;
(void)layoutSubviews
{
[super layoutSubviews];
float indentPoints = self.indentationLevel * self.indentationWidth;
self.contentView.frame = CGRectMake(
indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width - indentPoints,
self.contentView.frame.size.height
);
}
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.
NSLog(@"%@", self.contentView.subviews);
"<UIImageView: 0xa477030; frame = (23 7; 31 50); autoresize = TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xa477090>>"
I'm completely lost on why this keeps happening here. Must be some hidden constraint related to the iOS 6 new constraints stuff.
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":
This arranges your cell content properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With