gpt4 book ai didi

SwiftUI Nested NavigationView navigationBar消失

转载 作者:行者123 更新时间:2023-12-05 08:06:48 26 4
gpt4 key购买 nike

我有三个 ListView 。结构 MainMenuView: 查看 { @EnvironmentObject var 数据模型:DM

var body: some View {

return NavigationView{
List {
Matchup()
GameSettings()
EnteringGame()
}
}
}

内部匹配()

struct Matchup: View {
@EnvironmentObject var dataModel: DM

var body: some View {
Section(header: Text("MATCH-UP")
.fontWeight(.heavy)
.foregroundColor(Color("TPLightGrey"))
) {
NavigationLink(destination: TrendSingleSelect(
title: .constant("TEAM"),
col: .constant(self.dataModel.queryColumnTeam1),
items: .constant(self.dataModel.team1Values) ,
selection: self.$dataModel.team1ListValue
)) {
HStack {
Text("TEAM")
Spacer()
if dataModel.team1ListValue.count == 0 {
Text("IS ANY").foregroundColor(Color("TPLightGrey"))
} else {
Text( self.dataModel.team1ListValue.joined(separator: ", ")).foregroundColor(Color("TPOrange"))
}
}
}


}
.listRowBackground(Color("TPDarkGrey"))
.font(.system(size: 14))
.navigationBarTitle("", displayMode: .inline)
.navigationBarHidden(true)
}

请注意我隐藏了 NavBar。我想在用户点击一行时推送导航。:这是最终 View :

var body: some View {

return VStack {

List {
ForEach(self.items, id: \.self) { item in
SingleSelectionRow(title: item, isSelected: self.selection.contains(item)) {

if self.selection.contains(item) {
self.selection = []
}
else {
self.selection = [item]

}
self.queryCallback()
}
.listRowBackground(Color("TPDarkGrey"))
}//ForEach
}//list
.font(.system(size: 14))
}

.navigationBarHidden(false)
.navigationBarTitle(title)
.navigationBarItems(trailing:
Button(action: {
// Actions
self.reset()
}, label: {
Text("Clear")
}
)
)

}

发生的事情是:当我点击卖出时,我插入了那个部分。但是,当它插入时,我看到了导航栏,然后它就折叠起来了。但是,当我点击 View 中的任何内容以触发 View 重新加载时,它就会显示出来。

是什么导致导航栏崩溃?

最佳答案

在 MatchupView 中尝试这段代码:

struct Matchup: View {
@EnvironmentObject var dataModel: DM

var body: some View {
NavigationView { // attention hear************
Section(header: Text("MATCH-UP")
.fontWeight(.heavy)
.foregroundColor(Color("TPLightGrey"))
) {
NavigationLink(destination: TrendSingleSelect(
title: .constant("TEAM"),
col: .constant(self.dataModel.queryColumnTeam1),
items: .constant(self.dataModel.team1Values) ,
selection: self.$dataModel.team1ListValue
)) {
HStack {
Text("TEAM")
Spacer()
if dataModel.team1ListValue.count == 0 {
Text("IS ANY").foregroundColor(Color("TPLightGrey"))
} else {
Text( self.dataModel.team1ListValue.joined(separator: ", ")).foregroundColor(Color("TPOrange"))
}
}
}


}
.listRowBackground(Color("TPDarkGrey"))
.font(.system(size: 14))
} // attention hear************
.navigationBarTitle("", displayMode: .inline)
.navigationBarHidden(true)
}

关于SwiftUI Nested NavigationView navigationBar消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58330150/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com