Ambiguous Layout with UITextField in the contentView of a static UITableViewCell
Asked Answered
L

2

9

I am trying to add UITextFields to the contentViews of some static UITableViewCells. If I just add them directly to the cells in the storyboard, I get several of the following warning in Xcode 5:

Ambiguous Layout: Position is ambiguous for "Round Style Text Field".

If I then select the UITextFields and choose "Add Missing Constraints" in the storyboard, I then get this warning instead:

Misplaced View: Frame for "Round Style Text Field" will be different at run time.

In addition, I've tried adding constraints between the UITextField and the the contentView manually (by selecting those two views and trying to add a constraint), but it seems like none of the constraint options are available for that particular relationship (checkboxes are all disabled)

Here are some screenshots of the Storyboard: Static UITableViewCells with UITextFields in their contentView

Static UITableViewCells with UITextFields in their contentView, Added Missing Constraints

Leandra answered 30/9, 2013 at 23:52 Comment(0)
W
6

In the view controller panel to the left of storyboard there will be a yellow circle with an arrow Arrow, click it.

Then in the new panel click the yellow triangle with a circle in the middle.

You should get three options:

  1. Update Frame - this will move the UI element to match the orange dotted box
  2. Update Constraint - this will update the constraints to match the current UI element
  3. Reset to suggested constraints - Xcode will do what it thinks is right

In your case update constraints should work

Wove answered 1/10, 2013 at 0:59 Comment(4)
This fixed the ambiguous layout issue, but not the misplaced view issue.Leandra
To fix the misplaced view, open the size inspector for the misplaced view, and change the values of the frame rectangle to match the expected values listed in the warning.Carport
What if I don't want the frame to match the expected values?Leandra
Right now, when you run your application, the frames will match the expected values. The warning in the storyboard just tells you that what you'll get on the simulator/device is different from what appears in the storyboard. If you like where the frame is on the storyboard, you'll have to edit your constraints to match the frame.Carport
C
1

I was having similar issues - unable to add ("Pin") constraints to the embedded UITextField, getting warnings about it, etc. The OP didn't specify, but from the screenshot it appears the static UITableViewCell's Style is set to one of the pre-defined types ("Left Detail", in particular).

I found that setting the Table View Cell "Style" dropdown to "Custom" will magically enable adding constraints to the UITextField, at the cost of having to re-build the pre-defined cell style yourself - e.g. adding the UILabel(s) and matching their alignment to the other cells.

Contradance answered 11/3, 2014 at 4:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.