我创建了一个简单的项目来以编程方式使用约束移动一些组件,在这种情况下它只是一个 UIPickerView,但不幸的是我总是得到错误代码,我真的不明白它的含义是什么。
这是我的界面:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIPickerView *pickerView;
@end
这是我的实现:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLayoutConstraint *constraint = [NSLayoutConstraint
constraintWithItem:_pickerView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeTop
multiplier:1.0f
constant:216.f];
[self.view addConstraint:constraint];
}
这是我在调试器控制台上看到的:
2013-09-19 10:44:19.582 Constrain2[3092:c07] 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:0x71808f0 V:[UIPickerView:0x7180fd0(216)]>",
"<NSLayoutConstraint:0x71805d0 V:|-(216)-[UIPickerView:0x7180fd0] (Names: '|':UIView:0x7181290 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7184d50 h=--& v=--& V:[UIView:0x7181290(416)]>",
"<NSLayoutConstraint:0x7181740 UIPickerView:0x7180fd0.bottom == UIView:0x7181290.bottom>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x71808f0 V:[UIPickerView:0x7180fd0(216)]>
为什么我有这样的错误信息?我还尝试了本教程http://ioscreator.com/auto-layout-in-ios-6-adding-constraints-through-code/,我发现 UIButton 没有问题。但是,它不是使用情节提要来创建按钮。而在我的情况下,我通过情节提要放置 UIPickerView 。这是造成问题的原因吗?
谢谢你。