Swift Autolayout warnings and other warnings i do not understand - swift

The app allows users to post images/follow others etc.
So it works fine but i get the following warnings:
(I know some has to do with AutoLayout constraints but how do i know which is causing the problems?)
2015-07-05 17:19:37.701 Pixym[1271:72192] CUICatalog: Invalid asset name supplied:
2015-07-05 17:19:37.702 Pixym[1271:72192] Could not load the "" image referenced from a nib in the bundle with identifier "HP.Pixym"
2015-07-05 17:19:37.705 Pixym[1271:72192] 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)
(NSLayoutConstraint:0x7fa83b822a40 H:[UIImageView:0x7fa83b8529a0(300)],
NSLayoutConstraint:0x7fa83b85ccb0 H:[UIImageView:0x7fa83b8529a0]-(10)-| (Names: '|':UITableViewCellContentView:0x7fa83b871ff0 ),
NSLayoutConstraint:0x7fa83b8643d0 H:|-(10)-[UIImageView:0x7fa83b8529a0] (Names: '|':UITableViewCellContentView:0x7fa83b871ff0 ),
NSLayoutConstraint:0x7fa83b80ab00 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7fa83b871ff0(375)])
Will attempt to recover by breaking constraint
NSLayoutConstraint:0x7fa83b822a40 H:[UIImageView:0x7fa83b8529a0(300)]
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in UIKit/UIView.h may also be helpful.
Any help will be appreciated.

From the constraints, it seems you have an imageView with a width of 300 and a left and right padding of 10. That would work fine on iPhone 5(where the screen width is 320) but it will crash on iPhone 6/ 6 Plus because there the width is bigger.
What you need to do, is figure out how would you want the image to look like on all screens. Is the 10 pixels padding more important than the width or you would like it to always have a width of 300?
If you want the width, remove the other 2 constraints and add a center horizontal in container constraint for the image.
In the other case, just remove the width constraints and all should work.
Good luck!

Related

Xcode: horizontal constraints are not respected?

The result today is:
As you can see there is an error with the view which contains both Labels doesn't respect the constraint between icon and its.
Global constraints:
Did you see some configuration errors guys on constraints?
Aren't you getting constraint issue in your "Xib" or "Storyboard" because when I added the same constraints that you have used, I am getting constraint conflict issue.
After correcting it, It is like this now:
First the Texts layout.centerX = centreX is not required if you are adding leading and trailing.
Second Icon View.leading = leading + 16 if you want the icon view to stick to the left side.

Unable to simultaneously satisfy constraints - while trying to adjust dynamically cell height

I would like to adjust a cell dynamically to show all text which I have provided to a label inside of this particular cell. I have a custom cell and it cuts me the text and shows 3 dots at the end.
While trying this in viewdidload:
tableView.estimatedRowHeight = tableView.rowHeight
tableView.rowHeight = UITableViewAutomaticDimension
a) it destroys me the whole layout
b) shows me this error msg:
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)
(
"<NSLayoutConstraint:0x7faa6a5ab2f0 H:[UIImageView:0x7faa6a5ad100(135)]>",
"<NSLayoutConstraint:0x7faa6a5b9af0 UIImageView:0x7faa6a5ad100.leading == UITableViewCellContentView:0x7faa6a5acba0.leadingMargin>",
"<NSLayoutConstraint:0x7faa6a5b9c80 UILabel:0x7faa6a5b3f00'Mercedes-Benz G500 4x4\U00b2 s...'.trailing == UITableViewCellContentView:0x7faa6a5acba0.trailingMargin>",
"<NSLayoutConstraint:0x7faa6a5b9d20 H:[UIImageView:0x7faa6a5ad100]-(8)-[UILabel:0x7faa6a5b3f00'Mercedes-Benz G500 4x4\U00b2 s...']>",
"<NSLayoutConstraint:0x7faa6a5c09c0 'fittingSizeHTarget' H:[UITableViewCellContentView:0x7faa6a5acba0(34)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7faa6a5ab2f0 H:[UIImageView:0x7faa6a5ad100(135)]>
Is there a way to check out from this error message whats the matter here?

Error: Unable to simultaneously satisfy constraints

I get this error:
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)
(
"<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-| (Names: '|':UIView:0x1600a980 )>",
"<NSLayoutConstraint:0x1600ae80 V:|-(494)-[UIView:0x102021d0] (Names: '|':UIView:0x1600a980 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1600e8a0 h=-&- v=-&- UIView:0x1600a980.height == UIWindow:0x9e0ea30.height>",
"<NSAutoresizingMaskLayoutConstraint:0x9e2d130 h=--- v=--- V:[UIWindow:0x9e0ea30(480)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-| (Names: '|':UIView:0x1600a980 )>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in
<UIKit/UIView.h> may also be helpful.
the view that generates this error has 4 constrains for left/right/top/bottom and I can not delete any of them.
I have tried:
[View setTranslatesAutoresizingMaskIntoConstraints:NO];
with no result.
do you have any idea how to fix this?
Thank you!
The problem is in the vertical layout.
<NSAutoresizingMaskLayoutConstraint:0x9e2d130 h=--- v=--- V:[UIWindow:0x9e0ea30(480)]>
Autoresizing mask for a window. Fixed margins and size. You can't change this.
<NSAutoresizingMaskLayoutConstraint:0x1600e8a0 h=-&- v=-&- UIView:0x1600a980.height == UIWindow:0x9e0ea30.height>
Autoresing mask (fixed margins, resizable content). Probably the view of your controller. The height is 480 (set to be equal to the size of the window). Nothing to fix here.
<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-| (Names: '|':UIView:0x1600a980 )>
<NSLayoutConstraint:0x1600ae80 V:|-(494)-[UIView:0x102021d0] (Names: '|':UIView:0x1600a980 )>
You can notice that both constraints are doing something with the same view ([UIView:0x102021d0]) and have the same second view as a parameter (UIView:0x1600a980). The second view is our controller's view.
The two constraints define distances from edges of the second view. The first defines bottom (0). The second one defines top (494). If the superview's size is 480, that means [UIView:0x102021d0] would have height equal to -14 which triggers that exception.
How to fix it? Well, change the 494 constraint to the correct value. It's possible you don't even want the "top" constraint, maybe you want a fixed height instead.
How did the problem arise? You probably created your constraints for iPhone 5 and then you tried to run the app with iPhone 4. If you change the simulated size in your xib to iPhone 4, you should see the problem immediately.
There are still views that have translatesAutoresizingMaskIntoConstraints set to YES, apparently, otherwise you wouldn't be getting that message. It's probably the superview of the view that's giving you problems. Make sure that it also doesn't translate its autoresizing masks to constraints.

How to insert UIButton through code with AutoLayout feature enabled - iOS

I have been trying to insert a UIButton programatically, as I am using Autolayout I have done something like that...
[self.add_scroll_view addConstraints : [NSLayoutConstraint constraintsWithVisualFormat : #"V:[date_picker_btn]-[button(==date_picker_btn)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(date_picker_btn, button)]];
I have two questions here...
i) Button inserted is not the same width as date_picker_btn even though I mentioned button(==date_picker_btn).
ii) I have inserted properely, however below views should align accordingly down to accommodate new button... How to do that...
Thanx
When using the visual format language, the superview of the view for which the constraint is being described is represented by the | character.
Example:
V:|-20-[mybutton1(>=70#500)]-[mybutton2(==mybutton1)]-30-[mybutton3]-|
Refer this link
For first question I have mentioned V: so it means (==) will assign height not width. To set width it should start with H:.
Next question, To insert a button between two existing button need to handle already existing constraints, here above I have added new constraints only not handle old existing, so I have to delete the existing constraints, so that it avoid conflicts. Works fine.. Happy coding :)

Autolayout Constraint Error with a single constraint

I have a scence with a bunch of labels and buttons. When you tap on a button a view slides up from the bottom with controls in it, a kind of keyboard so to say. It "looks" like this:
-----------------------------
| |
| [Button 1] [ Slider 1 ] |
| |
| [Button 2] [ Slider 2 ] |
| |
-----------------------------
This "keyboard" is created at the very beginning when the view loads and the animation is done switching its heigth from 0 to its instrinsic content size. This escene only supports landscape mode and it took me quite a while to keep the "keyboard" on the view when the device rotates 180 degrees.
The problem I see pops up with either of the two following situations:
The device rotates 180 degrees.
The "keyboard" is called.
This problem as follows:
Unable to simultaneously satisfy constraints...
.
.
.
.
(
"<NSLayoutConstraint:0x718c6c0 UIButton:0x717e0d0.centerY == UISlider:0x717d9d0.centerY>",
"<NSLayoutConstraint:0x7190a00 UIButton:0x717e0d0.centerY == UISlider:0x717d9d0.centerY>"
)
The error log gives me this error twice, once for each set of button-slider.
What I think is weird is that the conflicting constraints are exactly the same. I thought I did some copy-paste mistake and added the same constraint twice, but it's not the case.
I'm guessing it has something to do with updateViewConstraints being called upon rotation and also whe I perform the animation, but I cannot see why only these constraints are affected since there are some more in this "keyboard" view.
All and all, this Autolayout is beign quite more difficult than Apples whants to claim. In my opinion, of course.
Any ideas?
EDIT: the constrains are set all in code using mainly the visual language format. The constrains of the controls inside the "keyboard" are added into the "keyboard" view which is the normal thing to do, I believe.
Just to try it out, I changed the problematic constraints and, instead to adding them to the "keyboard" subview, I added them to the self.view ("keyboard" superview). All the sudden, no more errors are shown.
Despite of that, I'd really like some discussion on the matter because I still don't know what's wrong and I just had a lucky shot. I'd really like to undestand it.
The fact that the conflicting constraints are exactly the same is in fact the error. With Auto Layout, you can't have a constraint twice. That will generate the error you see above.
Definitely, you have added the constraint twice. You can see this from the memory addresses. You have two different NSLayoutConstraint instances, 0x718c6c0 and 0x7190a00. However, the instances each refers to are both the same. That being that the vertical center centerY of your UIButton instance 0x717e0d0 should be in the middle of the UISlider 0x717d9d0.
Possibly your updateConstraints method has been called and you haven't checked to see if a constraint already exists before adding it again.
I don't know if this may help you but I just used this tutorial for setting up constraints to buttons and labels in my app