我有一个项目,我正在工作。我已经最小化的项目,以显示分层的意见,为这个问题的目的。
该项目在ScrollView中显示ShoeRowView。ShowRowView提供了一个名为“查看全部”的按钮。该按钮将用户带到ShoeSeeAllView。在那里有一个VStack,以ShoeViewLong视图的形式列出了所有不同的鞋子。
点击ShowViewLong时,用户将进入ShoeDetailView。
导航按预期工作,但问题是有两个后退按钮,一个在另一个下面。
我试过将@State变量与@Binding一起使用,但似乎无法使任何东西工作。
下面是代码:
struct Marketplace: View {
var body: some View {
NavigationView {
MarketplaceShoesView()
}
}
}
struct MarketplaceShoesView: View {
var body: some View {
ScrollView {
ShoeRowView(shoeData: shoe)
}
}
}
struct ShoeRowView: View {
@State private var isShowingDetailView = false
var shoeData: ShoeRow
var body: some View {
VStack {
HStack {
Text(shoeData.title)
HStack {
NavigationLink("", isActive: $isShowingDetailView){ShoesSeeAllView(shoeData: shoeData, shoe_id: shoeData.id)}
.navigationTitle("")
Button("See All") {
isShowingDetailView = true
}
Image(systemName: "chevron.right")
}
.padding(.trailing)
}
HStack {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 20) {
ForEach(shoeData.shoes ?? []) { shoe in
Text("Name of shoes")
}
}
.padding()
}
}
Divider()
}
}
}
struct ShoeSeeAllView: View {
var shoeData: ShoeStruct
var shoe_id: String
var body: some View {
NavigationView {
ScrollView(.vertical, showsIndicators: false) {
VStack {
VStack(spacing: 25) {
ForEach(shoeData.shoes ?? []) { shoe in
ShoeViewLong(shoeData: shoe)
}
}
}
}
}
.navigationTitle(shoeData.title)
}
}
struct ShoeViewLong: View {
var shoeData: ShoeStruct
var body: some View {
NavigationLink(destination: ShoeDetailView(shoe_id: shoeData.id ?? "")) {
HStack(spacing: 12){
Image("ShoeImage")
.resizable()
Text("Shoes Name")
}
}
}
}
struct ShoeDetailView: View {
var body: some View {
Text("This is shoes detail view")
}
}
我如何修复导航?它应该是这样的:
点击“查看全部”(在鞋行视图中)-〉鞋查看全部视图-〉点击鞋视图长-〉转到鞋详细视图。
在ShoeDetailView中,用户点击返回按钮-〉转到ShoesSeeAllView〉再次点击返回-〉转到MarketplaceShoesView(其中显示ShoeRowView)
1条答案
按热度按时间41zrol4v1#
问题与嵌套的NavigationView有关。从ShoeSeeAllView中删除NavigationView后,问题得到解决。