我有以下内容:
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(events) { event in
VStack {
Image(event.image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 100, height: 100)
.padding(55)
NavigationLink(destination: PostView()) {
Text(event.name)
.font(.system(.headline))
.padding(.bottom,20)
}
}
.padding()
.border(Color.black, width: 4)
.cornerRadius(10)
}
}
}
但是NavigationLink NavigationLink(destination: PostView()) {
不能带我到正确的视图吗?
我曾尝试将NavigationLink包裹在每个VStack周围,但这也无法带我进入视野
答案 0 :(得分:1)
我认为您没有使用“ NavigationView”。
NavigationView{
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach((1...10).reversed(), id: \.self) {_ in
VStack {
NavigationLink(destination: PostView()) {
Text("event.name")
.font(.system(.headline))
.padding(.bottom,20)
}
}
.padding()
.border(Color.black, width: 4)
.cornerRadius(10)
}
}
}
}