我试图让用户单击图像并将他们带到不同的视图,在该视图中它具有来自该视图的数组中的相同图像和文本,并且每次他们单击 scollview 中的图像时,视图都会弹出该信息。它将从数组中获取数据并在下一个视图中显示每个切换的正确项目。
struct practice: View {
@State var show = false
var place = Placeinfo
var body: some View {
VStack {
ScrollView(.horizontal) {
ForEach(place) { item in
HStack(spacing: 30) {
VStack {
HStack {
VStack {
Text(item.title).font(.headline)
Text(item.subtitle).font(.caption)
Button(action:{
self.show.toggle()
}) {
Image(item.image).renderingMode(.original)
}.sheet(isPresented: self.$show) { Detail() }
}
}
}.padding(.leading)
}
}
}
}
}
}
struct places : Identifiable{
var id = UUID()
var title: String = ""
var subtitle: String = ""
var image: String = ""
}
let Placeinfo = [
places(title: "beach", subtitle: "Cozumel",
image: "beach1"),
places(title: "beach2", subtitle: "Caribbean", image: "beach2"),
places(title: "beach3", subtitle: "CostaRica", image: "beach3")
]