I have a custom tableview cell created programmatically that consists of: a background view with an image 3 labels on the left and hand side one UISwitch on the right hand side. I want to be able to swipe and delete the cell. This works, however, when I swipe to bring up the delete button, the delete button pushes the background view (along with everything else) over as if it’s squishing the cell. How do I get it so that the background image doesn’t shrink?
I’ve searched around for this problem and some people said it had to do with autoresizing masks, but that didn’t seem to affect anything. I also don’t want to manually set the width of the cell in the layoutSubviews method as I saw one suggestion had.
Any ideas?
Thanks!
The problem, I’m guessing (since you didn’t post any code), is that you added all of these UI Elements as subviews of the cell, i.e. cell.backgroundColor = [UIColor someColor], [cell addSubview:label1], etc etc.
Here’s the thing: A cell’s view doesn’t know how to resize itself appropriately when things like editing mode occur. However, a cell’s contentView, which is a UIView, DOES know how to resize. For this reason, you need to add your labels, switches, etc. as subviews of the contentView, not the cell. Doing this will resize everything appropriately when you enter editing mode.