佚名通过本文主要向大家介绍了taylor swift,swift,swift code是什么意思,swift bic,taylor swift演唱会等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: swift约束问题
描述:
报错信息如下,请问我怎样写这种约束呢? 谢谢了。。。
2015-10-22 15:59:52.320 局[2527:116483] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7fcd22ced6a0 UIView:0x7fcd22ce3e90.width == UILayoutContainerView:0x7fcd22ccb5e0.width>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView(UIConstraintBasedLayout) _viewHierarchyUnpreparedForConstraint:] to debug.
2015-10-22 15:59:52.321 局[2527:116483] *** Assertion failure in -[UIView _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/NSLayoutConstraint_UIKitAdditions.m:590
2015-10-22 15:59:52.326 局[2527:116483] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Impossible to set up layout with view hierarchy unprepared for constraint.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010cf23f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010ec4adeb objc_exception_throw + 48
2 CoreFoundation 0x000000010cf23daa +[NSException raise:format:arguments:] + 106
3 Foundation 0x000000010d36d5ee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4 UIKit 0x000000010dff6b49 __120-[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]_block_invoke_2 + 254
5 UIKit 0x000000010dff6990 -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 387
6 UIKit 0x000000010dff6d7e -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 65
7 UIKit 0x000000010dff6ef7 -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 288
8 UIKit 0x000000010dff7119 -[UIView(UIConstraintBasedLayout) _addConstraint:] + 274
9 0x000000010cd347fa _TFCX19FFqEBqlCbGuahIddCEj19indexViewController11viewDidLoadfS0_FT_T_ + 1578
10 0x000000010cd348e2 _TToFCX19FFqEBqlCbGuahIddCEj19indexViewController11viewDidLoadfS0_FT_T_ + 34
11 UIKit 0x000000010d8d4dd4 -[UIViewController loadViewIfRequired] + 1198
12 UIKit 0x000000010d9191fe -[UINavigationController _layoutViewController:] + 54
13 UIKit 0x000000010d919ad2 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
14 UIKit 0x000000010d919c44 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
15 UIKit 0x000000010d91ae9d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
16 UIKit &n
描述:
let myDiyView = navTitleIndex(); //自定义的view
self.navigationItem.titleView = myDiyView.view; //想把view放在navItem中
let myconst = NSLayoutConstraint(item: myDiyView.view,
attribute: NSLayoutAttribute.Width,
relatedBy: NSLayoutRelation.Equal,
toItem: self.navigationController?.view,
attribute: NSLayoutAttribute.Width,
multiplier: 1,
constant: 0);
myDiyView.view.addConstraint(myconst); //添加约束,宽度等于窗体多宽度
报错信息如下,请问我怎样写这种约束呢? 谢谢了。。。
2015-10-22 15:59:52.320 局[2527:116483] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7fcd22ced6a0 UIView:0x7fcd22ce3e90.width == UILayoutContainerView:0x7fcd22ccb5e0.width>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView(UIConstraintBasedLayout) _viewHierarchyUnpreparedForConstraint:] to debug.
2015-10-22 15:59:52.321 局[2527:116483] *** Assertion failure in -[UIView _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/NSLayoutConstraint_UIKitAdditions.m:590
2015-10-22 15:59:52.326 局[2527:116483] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Impossible to set up layout with view hierarchy unprepared for constraint.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010cf23f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010ec4adeb objc_exception_throw + 48
2 CoreFoundation 0x000000010cf23daa +[NSException raise:format:arguments:] + 106
3 Foundation 0x000000010d36d5ee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4 UIKit 0x000000010dff6b49 __120-[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]_block_invoke_2 + 254
5 UIKit 0x000000010dff6990 -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 387
6 UIKit 0x000000010dff6d7e -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 65
7 UIKit 0x000000010dff6ef7 -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 288
8 UIKit 0x000000010dff7119 -[UIView(UIConstraintBasedLayout) _addConstraint:] + 274
9 0x000000010cd347fa _TFCX19FFqEBqlCbGuahIddCEj19indexViewController11viewDidLoadfS0_FT_T_ + 1578
10 0x000000010cd348e2 _TToFCX19FFqEBqlCbGuahIddCEj19indexViewController11viewDidLoadfS0_FT_T_ + 34
11 UIKit 0x000000010d8d4dd4 -[UIViewController loadViewIfRequired] + 1198
12 UIKit 0x000000010d9191fe -[UINavigationController _layoutViewController:] + 54
13 UIKit 0x000000010d919ad2 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
14 UIKit 0x000000010d919c44 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
15 UIKit 0x000000010d91ae9d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
16 UIKit &n