Re: Autolayout help please


davelist@...
 

On Dec 30, 2020, at 10:25 PM, tridiak <tridiaknz@gmail.com> wrote:

I have an iPad app with ~60 labels and text fields.
Whenever I start to edit one of the text fields, I get this:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x281d4b980 h=--& v=--& _UIButtonBarButton:0x102b7a5c0.height == 0 (active)>",
"<NSLayoutConstraint:0x281d4efd0 _UIUCBKBSelectionBackground:0x102b7b340.bottom == _UIButtonBarButton:0x102b7a5c0.bottom - 6 (active)>",
"<NSLayoutConstraint:0x281d4ef30 V:|-(6)-[_UIUCBKBSelectionBackground:0x102b7b340] (active, names: '|':_UIButtonBarButton:0x102b7a5c0 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x281d4efd0 _UIUCBKBSelectionBackground:0x102b7b340.bottom == _UIButtonBarButton:0x102b7a5c0.bottom - 6 (active)>
<snip other auto layout errors>


The app has no top or bottom bar (single page app option upon project creation).
I have manually tried to set & clear translatesAutoresizingMaskIntoConstraints . No change.

I have only one IBAction set for now.
Because of this mess the IBAction is not called. IBAction presence makes no difference.

I am not manually creating 100+ constraints for all these controls.
'Adding Missing Constraints' does not help. In one case it creates errors.

Is there some obscure setting that needs to be changed?

Years ago I could create an interface like this and none of this autolayout crap would happen.
Note this app is for personal use, it is not intended for the app store.

Xcode Version 12.2 (12B45b).
OS 10.15.7 (19H114).
iPad OS 14.2.


Thanks for any help
Mark

If you're creating the views in code then for each UIView subclass you create, you need to set translatesAutoresizingMaskIntoConstraints to false.

If you're create the views in a storyboard then you don't need to do anything with translatesAutoresizingMaskIntoConstraints.

You said "I am not manually creating 100+ constraints for all these controls." - are you creating any constraints for them?

Since it's a personal app and exact aesthetics aren't important, you may find it easier to embed the labels and textfields inside UIStackViews.

I don't know what your IBAction is, but I wouldn't think constraints would affect it.

HTH,
Dave

Join xcode@apple-dev.groups.io to automatically receive all group messages.