【发布时间】:2021-07-26 01:08:45
【问题描述】:
我正在尝试使用 SwiftUI 让每个项目在列表中显示它自己的 detailView。但是现在,我被卡住了,因为它只为任何项目显示相同的 detailView。有人知道该怎么做吗? 这是我现在拥有的代码:
struct PastryListView: View {
@State private var isShowingDetailView = false
@State private var selectedPastry : Pastry?
@State private var selection: Int? = nil
var body: some View {
ZStack {
NavigationView {
List(MockData.pastries) { Pastry in
HStack {
Image(Pastry.image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 180, height: 200)
VStack {
Text(Pastry.name)
.font(Font.custom("DancingScript-Regular", size: 30))
.fontWeight(.medium)
}
.padding(.leading)
}
.onTapGesture {
selectedPastry = Pastry
isShowingDetailView = true
}
}
.navigationTitle("???? Pastries")
}
if isShowingDetailView { Pastry2DetailView(isShowingDetailView2: $isShowingDetailView, pastry: MockData.samplePastry2)
}
}
} }
【问题讨论】:
标签: swift xcode listview swiftui