更新时间:2022-05-15 02:45:52
应该只有一张图纸,因此这里是可行的方法-使用另一张图纸修改器并通过选择激活它
There should be only one sheet, so here is possible approach - use another sheet modifier and activate it by selection
已通过Xcode 12/iOS 14(与iOS 13兼容)进行了测试
Tested with Xcode 12 / iOS 14 (iOS 13 compatible)
extension Int: Identifiable {
public var id: Int { self }
}
struct ContentView: View {
@State private var selectedMovie: Int? = nil
var movies = ["Harry potter", "Mad Max", "Oblivion", "Memento"]
var body: some View {
NavigationView {
List {
ForEach(0 ..< movies.count) { movie in
HStack {
Text(self.movies[movie])
Image(systemName: "heart")
}
.onTapGesture {
self.selectedMovie = movie
}
}
}
.sheet(item: self.$selectedMovie) {
Text(self.movies[$0])
}
}
}
}