我正在尝试在我的 UIView 中创建一个 TGMapView。创建 TMMapView 后,我收到此错误:
2019-02-04 14:47:22.288241-0500 IOSDemoApp[8325:289276] [LayoutConstraints] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x6000015f0b40 _UILayoutGuide:0x7fe52fc0e750.leading == TrimbleMaps.TMMapView:0x7fe52fc0e320.leading (inactive)>
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.
2019-02-04 14:47:22.288477-0500 IOSDemoApp[8325:289276] [LayoutConstraints] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x6000015f0c80 _UILayoutGuide:0x7fe52fc0e750.top == TrimbleMaps.TMMapView:0x7fe52fc0e320.top (inactive)>
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.
2019-02-04 14:47:22.288642-0500 IOSDemoApp[8325:289276] [LayoutConstraints] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x6000015f0e10 _UILayoutGuide:0x7fe52ff05670.leading == TrimbleMaps.TMMapView:0x7fe52fc0e320.leading (inactive)>
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.
2019-02-04 14:47:22.310967-0500 IOSDemoApp[8325:289276] [LayoutConstraints] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x6000015f0f00 TrimbleMaps.TMMapView:0x7fe52fc0e320.bottom == _UILayoutGuide:0x7fe52ff05670.bottom (inactive)>
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.
我在这里尝试创建的 UIView 是 TGMapView 似乎并不重要。如果我尝试创建一个普通的旧 UIView 我会遇到同样的问题。
public class Sample: UIView {
private var tangramMapView: TGMapView!
public var trivialView: UIView!
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// both have the same warning/error
guard let tangramMapView = TGMapView(coder: aDecoder) else { return nil }
trivialView = UIView.init(coder: aDecoder)
setup()
}
}
当我运行它时,TGMapView 和 UIView 初始化都会发出相同的警告(复制到上面)。我希望没有警告,并且 UIViews 约束在setup()
. 我在setup()
.
将 UIViews 添加到我不知道的 UIViews有什么特别之处吗?我做错了顺序吗?在superView init完成之前不能完成吗?
编辑:
为什么要使用示例视图的 aDecoder 对其进行初始化?
不知道。我在情节提要中设置了它,并且在我的单视图应用程序中将视图设置为Sample
视图。在调试器中,我可以看到aDecoder
正在调用 init。我不能告诉你为什么其他人不是。