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