Auto Layout Constraints Issue in UITableView

With the help of Auto Layout I had implemented the views programmatically to handle the different design layouts for iPhone 4, 5 and 6. The program works good in all the views except UITableView. I am getting the below constraints issue in my console.

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:0x178be740 V:|-(0)-[UILabel:0x165413b0]   (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
 "<NSLayoutConstraint:0x178b5910 V:[UILabel:0x165413b0(40)]>",
 "<NSLayoutConstraint:0x178a0ac0 V:[UILabel:0x165413b0]-(NSSpace(8))-[UIView:0x1789e5d0]>",
 "<NSLayoutConstraint:0x178a0af0 V:[UIView:0x1789e5d0(1)]>",
 "<NSLayoutConstraint:0x178a0b20 V:[UIView:0x1789e5d0]-(0)-|   (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
 "<NSLayoutConstraint:0x178ab4f0 V:|-(10.5)-[UIImageView:0x1789e4c0]   (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
 "<NSLayoutConstraint:0x178b9ca0 V:[UIImageView:0x1789e4c0(19)]>",
 "<NSLayoutConstraint:0x178b9cd0 V:[UIImageView:0x1789e4c0]-(10.5)-|   (Names: '|':UITableViewCellContentView:0x16541ac0 )>"
)

I tried with several posts and failed to get rid of the constraints. Could any one suggest on this?

Updated code

//MyCustomeListCell.h
UILabel *listTitle;
UIImageView *listImage;
UIView *listSplitter;

//MyCustomListCell.m
 NSDictionary *viewsDictionary =@{@"listTitle": self.listTitle,@"listImage" : self.listImage,@"listSplitter": self.listSplitter};
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[listTitle(40)]-[listSplitter(1)]|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[listSplitter]|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10.5-[listImage(19)]-10.5-|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-15-[listTitle]-15-[listImage(13)]-20-|" options:0 metrics:nil views:viewsDictionary]];

Answers


This format string,"V:|-10.5-[listImage(19)]-10.5-|" is saying that you want the imageView to be 10.5 points separated from the top and bottom of its superview, but also to be 19 points tall. So, unless the superview is exactly 40 points tall in all screen sizes, this will cause an error.

Same with this one, "V:|[listTitle(40)]-[listSplitter(1)]|" This one will only work if the superview is 49 points tall (40 + 8 for the dash (I think) + 1).

To fix these, you need to not have the system so constrained. Depending on what you want, you could remove the "|" from one end of those format strings, or get rid of the size setting.


There is much simpler way, without using constrains but autoresizingMask:

self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

Need Your Help

Media query doesn't work at all

html css media-queries

After completing my whole website I was introduced to media queries as a way of making my website responsive. The thing is that even though I found many resources on Media queries and I know what t...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.