Moriya Moriya - 2 years ago 180
Swift Question

UITableViewCell subclass layout in edit mode

I'm seeing some very strange behaviour in the layout of my custom cell when tableView enters edit mode.

It seems like the content view becomes very tiny and is moved to the right of the cell.

example image
Here's the cells in normal mode to the left and in edit mode to the right.

Does anyone know what might be happening here?


Code for a very simplified version of this issue can be fetched from dropbox here

Answer Source

Edit :

Try commenting out below line.

cell.layoutMargins = UIEdgeInsets(top: 0, left: UIScreen.mainScreen().bounds.width, bottom: 0, right: 0)

Earlier Answer :

This could be happening because of your Storyboard constraints.

While in UITableView edit mode, the red button appears in the right and the layout squeezes towards the left. Hence The constraints that were set rigidly for normal cell mode are no longer valid and the cell is collapsing to the right. You should set the constraints flexible enough for the UI change that is happening during the edit mode. You can check the console and see the error messages that happen during edit mode.

For example setting your Line View element leading space to superview less than or equal to instead of equal will improve your view, although not completely resolve your issue. But perhaps you can fix rest of them yourself :-)

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download