2015-12-23 3 views
5

UITableViewのヘッダーにAutolayoutを設定するコードがあります。このコードはiOS9では正常に動作していますが、iOS8ではUIViewAlertForUnsatisfiableConstraintsが発生します。iOS8では自動レイアウトエラーですが、iOS9では無効

-(NSArray *)layoutConstraints 
{ 
    NSMutableArray * result = [NSMutableArray array]; 

    NSDictionary * views = [self views]; 

    NSDictionary * metrics = [self metrics]; 

    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[section]-20-|" 
                     options:0 
                     metrics:nil 
                      views:views]]; 

    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[section]|" 
                     options:0 
                     metrics:nil 
                      views:views]]; 


    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[subtitleLabel]-20-|" 
                     options:0 
                     metrics:nil 
                      views:views]]; 

    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[titleLabel]-20-|" 
                     options:0 
                     metrics:metrics 
                      views:views]]; 

    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[sectionContainer]|" 
                   options:0 
                   metrics:nil 
                    views: views]]; 

    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[sectionContainer(section_heigth)]-[subtitleLabel]-[titleLabel]-20-|" 
                       options:0 
                       metrics:metrics 
                       views:views]]; 

    return result; 
} 

補助方法は以下のとおりです。

-(NSDictionary *)views 
{ 
    return @{ @"sectionContainer": self.sectionContainer, 
        @"section": self.section, 
        @"subtitleLabel": self.subtitleLabel, 
        @"titleLabel": self.titleLabel 
        }; 
} 

-(NSDictionary *)metrics 
{ 
    return @{@"section_heigth" : @(HEIGHT_FOR_HEADER_IN_SECTION), 
       @"margin"   :@20 
      }; 
} 

発生した例外がある:

私はiOS8から変更は何も見つかっていない自動レイアウトのドキュメントを見ると
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:0x1b954150 H:|-(20)-[UILabel:0x12834d40'Ability to Round'] (Names: '|':_UITableViewHeaderFooterContentView:0x239a5510)>", 
    "<NSLayoutConstraint:0x1b954190 H:[UILabel:0x12834d40'Ability to Round']-(20)-| (Names: '|':_UITableViewHeaderFooterContentView:0x239a5510)>", 
    "<NSLayoutConstraint:0x1b94f390 'UIView-Encapsulated-Layout-Width' H:[_UITableViewHeaderFooterContentView:0x239a5510(0)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1b954190 H:[UILabel:0x12834d40'Ability to Round']-(20)-| (Names: '|':_UITableViewHeaderFooterContentView:0x239a5510)> 

このコードに影響を与える可能性のあるiOS9何か不足していますか?

+0

ios9とios8の場合、同じシミュレータを使用していますか?中断しているラベルは 'subtitleLabel'か' titleLabel'ですか? – Sana

+0

それは壊れている 'titleLabel'です。私は同じシミュレータ(iPad2)を使用しています – ppaulojr

+0

全体のビューをペーストするかコントローラコードを表示できますか?vfl – Sana

答えて

0

ここでの問題は制約自体ではありません。少なくともコードの部分では、私たちに提供しました。

"<NSLayoutConstraint:0x1b94f390 'UIView-Encapsulated-Layout-Width' H:[_UITableViewHeaderFooterContentView:0x239a5510(0)]>" 

この種のconstriantsはシステムによって追加され、ビューが既に設定されると削除されます。私の推測では、あなたのコードのどこかにレイアウト・パスを強制していると思います(layoutIfNeededなど)。 そのような場合は削除してください。代わりにsetNeedsLayoutを使用してください。その方法は、ビューをMUST_BE_LAYOUTED_IN_THE_NEXT_LAYOUT_PASSとマークしますが、準備が整う前に強制的に実行しません。

関連する問題