Pascal
Pascal

Reputation: 1305

Swift: Problems with PrototypeCells in UITableViewController

I have a problem with my iOS Application. I'm using Swift and XCode 6.3. I have a UITableViewController in my application and in this TableView I've created a prototype cell (Custom). In the design it looks like this:

enter image description here

This is how I want the cells (left the title and on the right a switch in every cell).

But my problem is, if I run the project it looks like this on my iPhone:

enter image description here

What do I have to do that the cell is looking like my prototype cell? Thank you in advance!

Upvotes: 1

Views: 152

Answers (1)

Aviel Gross
Aviel Gross

Reputation: 9975

Your title label is probably overlapping the switch view. You need to set an auto-layout constraint of horizontal spacing between the right edge (trailing in auto layout language...) of the label and the left edge (leading) of the switch view.

1. ctrl+drag from the label to the switch:

enter image description here

2. pick horizontal spacing:

enter image description here

  1. then change the relation to be Greater than or equal instead equal, and set the constant to whatever minimum distance you want to have between the label and the switch:

enter image description here

  1. add all other missing constrains...

EDIT:
To get the label without having to subclass UITableViewCell you can set a tag to the label:
enter image description here

Then inside cellForRow.. you can get it with myCell.viewWithTag(999)

Upvotes: 3

Related Questions