2015-12-23 14 views
5

पर मेरे पास एक कोड है जो UITableView के शीर्षलेख में ऑटोलायआउट सेट करता है। यह कोड आईओएस 9 पर ठीक काम कर रहा है लेकिन आईओएस 8 पर यह UIViewAlertForUnsatisfiableConstraints उठाता है।आईओएस 8 पर ऑटो लेआउट त्रुटि लेकिन आईओएस 9

-(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 
      }; 
} 

अपवाद उठाया है:

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)> 

ऑटो लेआउट के लिए प्रलेखन मैं कुछ भी नहीं पाया है कि iOS8 से बदलकर में खोज रहे हैं आईओएस 9 जो इस कोड को प्रभावित कर सकता है। क्या मैं कुछ भूल रहा हूँ?

+0

क्या आप एक ही सिमुलेटर का उपयोग कर रहे हैं? तोड़ने वाला लेबल 'उपशीर्षक लेबल' या 'शीर्षक लेबल' है? – Sana

+0

यह 'शीर्षक लेबल' है जो टूट रहा है। मैं एक ही सिम्युलेटर (आईपैड 2) – ppaulojr

+0

का उपयोग कर रहा हूं क्या आप संपूर्ण दृश्य पेस्ट कर सकते हैं या नियंत्रक कोड देख सकते हैं ... क्योंकि मैं आपके वीएफएल – Sana

उत्तर

0

आपकी समस्या यहां बाधाएं नहीं हैं। कम से कम कोड के उस हिस्से में आपने हमें प्रदान किया है।

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

इस प्रकार के constriants सिस्टम द्वारा जोड़े जाते हैं, और दृश्य को पहले से स्थापित होने के बाद हटा दिया जाता है। मेरा अनुमान है कि आप अपने कोड में किसी लेआउट पास को मजबूर कर रहे हैं (उदाहरण के लिए लेआउट IfNeeded उदाहरण के लिए)। यदि ऐसा है, तो इसे हटा दें। इसके बजाय setNeedsLayout का उपयोग करें। वह विधि दृश्य को MUST_BE_LAYOUTED_IN_THE_NEXT_LAYOUT_PASS के रूप में चिह्नित करेगी लेकिन इसे तैयार होने से पहले इसे मजबूर नहीं करेगी। I129 और ios8 के लिए

संबंधित मुद्दे