IOS: Constraint crashes in iOS7 system using AutoLayout in TableView with masonry

Source: Internet
Author: User

First, a crash scenario occurs:

A crash occurs when you create a header view for TableView, that is, Tableheaderview, and then use masonry and switch to the ios7/7.1 system to add constraints to all the child views in Tableheaderview.

Second, crash log:

Terminating app due to uncaught exception ' nsinternalinconsistencyexception ', Reason: ' Auto Layout still required after ex Ecuting-layoutsubviews. UITableView ' s implementation of-layoutsubviews needs to call super.

Third, the cause of the crash:

It is said that AutoLayout is a iOS6 bug, in the iOS7 has been resolved, but the actual use or encountered the problem, there may be no repair.

Iv. Solutions:

(1) The Setframe method is used to calculate the relative position of the sub-view in the layoutsubviews.

(2) using the masonry framework, not in Layoutsubviews, but instead customizing a method, such as-(void) Setupconstraint, and then AutoLayout constraints in the method, When you add a child view in init or initframe, you call the method, which is also [self setupconstraint].

(3) The masonry framework is used in the Layoutsubviews, which is autolayout constrained in the method, but must be placed before the [super Layoutsubviews] method.

(4) swizzling. online More than the saying is to add a classification to UITableView, in the classification of the +load method, and then the load method used swizzling to adjust the function of the order of execution, to ensure that after the completion of AutoLayout call super- Layoutsubviews. This is a link to this method: about Swizzling.

V. Additional additions:

On iOS7, it's no problem to use AutoLayout to add a child view to Uiscrollview.

IOS: Constraint crashes in iOS7 system using AutoLayout in TableView with masonry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.