2015-10-26 13 views
0

這是另一個「我以前完成並在其他項目中工作,但不能爲我的生活弄清楚什麼是錯誤」的情況。tableViewCell中編程式NSLayout約束的問題

我不斷收到奇怪的約束錯誤,不知道是因爲iOS 9還是什麼,但我想知道是否有人可以幫助我。謝謝!

我的表視圖細胞類

#import "TableViewCell.h" 

@implementation TableViewCell 

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
if (self) { 

    self.translatesAutoresizingMaskIntoConstraints = NO; 

    self.recipeImageView = [UIImageView new]; 
    self.recipeImageView.image = [UIImage imageNamed:@"imagePickerBackground"]; 
    self.recipeImageView.layer.cornerRadius = 20; 
    self.recipeImageView.layer.borderColor = [[UIColor blackColor]CGColor]; 
    self.recipeImageView.layer.borderWidth = 1; 
    self.recipeImageView.layer.masksToBounds = YES; 
    [self addSubview:self.recipeImageView]; 

    self.descriptionLabel = [UILabel new]; 
    self.descriptionLabel.text = @"description"; 
    self.descriptionLabel.font = [UIFont fontWithName:@"Chalkduster" size:12]; 
    self.descriptionLabel.textColor = [UIColor blackColor]; 
    self.descriptionLabel.layer.cornerRadius = 20; 
    self.descriptionLabel.layer.borderWidth = 1; 
    self.descriptionLabel.layer.masksToBounds = YES; 
    self.descriptionLabel.layer.borderColor = [[UIColor blackColor]CGColor]; 
    [self addSubview:self.descriptionLabel]; 

    NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(_descriptionLabel, _recipeImageView); 

    NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_recipeImageView]-10-|" options:0 metrics:nil views:viewsDictionary]; 

//  NSArray *constraintsTwo = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[_recipeImageView]-10-|" options:0 metrics:nil views:viewsDictionary]; 

    NSLayoutConstraint *equalConstraint = [NSLayoutConstraint constraintWithItem:self.descriptionLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.recipeImageView attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; 

    NSArray *verticalConstrains = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[_recipeImageView(==200)]-10-[_descriptionLabel(==70)]-10-|" options:0 metrics:nil views:viewsDictionary]; 

    [self addConstraints:constraints]; 
//  [self addConstraints:constraintsTwo]; 
    [self addConstraints:verticalConstrains]; 
    [self addConstraint:equalConstraint]; 

} 

return self; 
} 

@end 

這裏是在視圖控制器的編程註冊方法(數據源和表視圖的代表)

鑑於沒有負載

- (void)viewDidLoad { 
[super viewDidLoad]; 

self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; 
self.tableView.delegate = self; 
self.tableView.dataSource = self; 
[self registerTableView:self.tableView]; 
[self.view addSubview:self.tableView]; 

[self.tableView reloadData]; 

[self setUpNavigationBar]; 

} 

寄存器方法

- (void)registerTableView:(UITableView *)tableView { 

[tableView registerClass:[TableViewCell class] forCellReuseIdentifier:@"cell"]; 

} 

小區排在指數路徑

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

return cell; 

} 

高度行(設定爲300)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

return 300; 
} 

錯誤堆棧(它不會崩潰,所以我不能把一個斷點,但視圖在細胞沒有顯示出來)

2015年10月26日15:22:05.524配方日記[33894:1375043]無法 同時滿足約束條件。以下列表中的至少一個 約束可能是您不想要的約束之一。試試這個:(1) 看看每個約束,並試圖找出你不期望的; (2)找到添加了不需要的約束或約束的代碼並對其進行修復。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

請在UIViewAlertForUnsatisfiableConstraints 一個象徵性的斷點趕上這在調試器。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.525食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。(注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」, 「」)

將嘗試恢復通過打破約束

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲此斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.664食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

請在UIViewAlertForUnsatisfiableConstraints 一個象徵性的斷點趕上這在調試器。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.744食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」, 「」, 「」, 「」)

將嘗試打破約束

請在UIViewAlertForUnsatisfiableConstraints 一個象徵性的斷點趕上這在調試器來恢復。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.746食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。(注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲該斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.747食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲該斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.759食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」, 「」)

將嘗試恢復通過打破約束

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲此斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.760食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。(注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲該斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.761食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」, 「」, 「」, 「」)

將嘗試打破約束

請在UIViewAlertForUnsatisfiableConstraints 一個象徵性的斷點趕上這在調試器來恢復。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.767食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲該斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.769食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。(注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲該斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.804食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」, 「」)

將嘗試恢復通過打破約束

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲此斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.806食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲該斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.839食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。(注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」, 「」, 「」, 「」)

將嘗試打破約束

請在UIViewAlertForUnsatisfiableConstraints 一個象徵性的斷點趕上這在調試器來恢復。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。 2015-10-26 15:22:05.842食譜 日記[33894:1375043]無法同時滿足約束條件。 以下列表中的至少一個約束可能是您不需要的一個 。嘗試這一點:(1)看看每個約束,並嘗試找出你不期望的 ; (2)找到添加了不想要的約束或約束並修復它的代碼。 (注意:如果你看到 NSAutoresizingMaskLayoutConstraints,你不明白,請參閱 到文檔中的UIView財產 translatesAutoresizingMaskIntoConstraints)( 「」, 「」)

將嘗試打破約束 恢復

在UIViewAlertForUnsatisfiableConstraints 上設置一個符號斷點,以便在調試器中捕獲該斷點。 中列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能有所幫助。從調試器的消息: 終止由於信號15

回答

0

我計算出來

代替

self.translatesAutoresizingMaskIntoConstraints = NO; 

它應該是

self.recipeImageView.translatesAutoresizingMaskIntoConstraints = NO; 
self.descriptionLabel.translatesAutoresizingMaskIntoConstraints = NO;