Swipe with UITableViewCell: cell shrinks

I have a custom tableview cell created programmatically, which consists of: a background view with an image of 3 labels on the left and one UISwitch side on the right side. I want to be able to swipe in and out of a cell. This works, however, when I sit down to invoke the delete button, the delete button nudges the background view (along with everything else) as if it were squishing the cell. How do I do this so that the background image doesn't shrink?

I searched for this issue and some people said it was related to mask automation but it didn't make any difference. I also don't want to manually set the cell width in the layoutSubviews method as I saw one suggestion.

Any ideas? Thank!

+3


source to share


2 answers


The problem I assume (since you haven't posted any code) is that you added all these UI elements as subzones of the cell, ie cell.backgroundColor = [UIColor someColor], [cell addSubview: label1], etc.



Here's the thing: the view of the cell doesn't know how to properly resize when things like edit mode happen. However, the content of the cellView, which is a UIView, knows how to resize. For this reason, you need to add shortcuts, switches, etc. As subzones of the content of the View, not the cells. In doing so, you are making changes to edit mode.

+6


source


I just solved a similar problem. It has nothing to do with the presentation of the content . When you've added the UIImageView to a cell, either in the UI designer or as a storyboard, it has all the springs and struts. You will notice that your UILabels only have top and left pillars.

Removing the inner springs and the right / bottom pillar for the UIImageView in the UITableView cell will prevent them from collapsing with the delete scroll button.



UItableview cell squishes uiimage fix

+4


source







All Articles