我在使用 NavigationView 这个组件的时候抛出了以下信息,要如何排查,我也是第一次写 swift ,完全不知所云,网上虽然也有人遇到了差不多的问题,但是每个人的情况都不一样。
2022-04-08 15:08:39.897732+0800 Memorize[59861:7906093] [LayoutConstraints] 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.
(
"<NSLayoutConstraint:0x6000036c65d0 'BIB_Leading_Leading' H:|-(0)-[_UIModernBarButton:0x15b71cb40] (active, names: '|':_UIButtonBarButton:0x15b71a0b0 )>",
"<NSLayoutConstraint:0x6000036c7340 'UINav_static_button_horiz_position' _UIModernBarButton:0x15b71cb40.leading == UILayoutGuide:0x600002ce6f40'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x6000036c7390 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x15b71a0b0]-(6)-[UILayoutGuide:0x600002ce6e60'UINavigationBarItemContentLayoutGuide'] (active)>",
"<NSLayoutConstraint:0x6000036d8230 'UINavItemContentGuide-trailing' UILayoutGuide:0x600002ce6e60'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x15b714790.trailing (active)>",
"<NSLayoutConstraint:0x6000036d9f90 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x15b714790.width == 0 (active)>",
"<NSLayoutConstraint:0x6000036d85f0 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600002ce6f40'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarContentView:0x15b714790 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000036c65d0 'BIB_Leading_Leading' H:|-(0)-[_UIModernBarButton:0x15b71cb40] (active, names: '|':_UIButtonBarButton:0x15b71a0b0 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
我把 swiftUI 官方的教程也跑了下,也是会抛出这些错误,我现在暂时根据 stackoverflow 的回答关闭了这些信息,想问下各位这个可不可以解决
关闭的代码是
UserDefaults.standard.setValue(false, forKey:"_UIConstraintBasedLayoutLogUnsatisfiable")
项目中抛出错误的代码是
struct MemoryGameList: View {
var body: some View {
NavigationView{
List{
ForEach(MemoryGameHandler.emojiDatas){ emoji in
NavigationLink{
EmojiMemoryGameView(
emojiGame: MemoryGameHandler(with: emoji.theme),
theme: emoji.theme
)
} label: {
MemoryGameRow(emoji: emoji)
}
.tag(emoji)
}
}
.navigationTitle("Game List")
Text("Select a Game")
}
}
}
struct MemoryGameRow: View {
var emoji: EmojiData
var body: some View {
HStack{
Text(emoji.theme.rawValue)
Text(datasSubList.joined())
}
.padding(.vertical, 4)
}
var datasSubList: [String]{
Array(emoji.datas[...10])
}
}
struct MemoryGameRow_Previews: PreviewProvider {
static var previews: some View {
MemoryGameRow(emoji: MemoryGameHandler.emojiDatas[0])
}
}
1
chipmuck 2022-04-15 11:20:54 +08:00 2
给 NavigationView 添加一个 .navigationViewStyle(.stack) 的 modifier 试试看。
|
2
ChrisFreeMan OP @chipmuck 起作用了,多谢兄弟,强迫症给你治好了
|