在我的帮助下,Auto Layout
我以编程方式实现了视图,以处理 iPhone 4、5 和 6 的不同设计布局。该程序在除UITableView
. 我在控制台中遇到以下约束问题。
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 )>"
)
我尝试了几个帖子,但未能摆脱限制。有人可以对此提出建议吗?
更新代码
//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]];