我正在为Item设置NavigationLink,但无法处理消失的图像。
struct Items: View {
var landmarks: [Landmark]
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(landmarks) { landmark in
//加了这个导航就看不到图片了,CategoryHome 也不显示图片,
//NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
Item(landmark: landmark)
//}
}
}
}
}
}
答案 0 :(得分:1)
您必须将Scrollview
嵌入到NavigationView
中,否则它将无法正常工作
struct Items: View {
var landmarks: [Landmark]
var body: some View {
NavigationView {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(landmarks) { landmark in
//加了这个导航就看不到图片了,CategoryHome 也不显示图片,
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
Item(landmark: landmark)
}
}
}
}
}
}
}
Here是用于创建导航的苹果教程,SwiftUI