Autolayout in Table View

I can't wrap my head around getting autolayout to work in a prototype cell inside a table view.
I've placed a button in the center of my cell.

Then I've centered it horizontally and vertically in the container but when I switch to a different iPhone the button moves and it won't stay centered. Why does it behave like that? What am I missing? I've tried all kinds of constraints.

Replies

Could you show the constraints you have defined ?


And how you have defined the cell subclass.

This is my configuration. I think I've found a solution. If I use a prepackaged Table View Controller from IB, autolayout works fine and the button stays centered. Whereas if I embed a Table View in a generic View Controller I get a different behaviour. Could it be the solution then? Why is it like so?

You've aligned the left edge of the button to be centered. So text will start at the center of the cell and continue to the right. Control-drag from the middle area of the button, then choose 'center horizontally in container'.


Also, check that your constraints from the button are being attached to the content view.

I replied 2 days ago but it's still currently being moderated. Hello Apple?
By the way, I think I've found a solution. If I use a prepackaged Table View Controller from IB, autolayout works fine and the button stays centered. Whereas if I embed a Table View in a generic View Controller I get a different behaviour. Could it be the solution then? Why is it like so?

These are my constraints.The button keeps moving whenever I change the device.
I've posted above a possible solution to this problem. But I still missing why it behaves like so when I embed a Table View in a generic VC