【发布时间】:2020-12-21 13:08:35
【问题描述】:
我在 SwiftUI 中有以下代码
struct AuthorView: View {
let authors = ["a","b","c"]
@State private var selectedAuthor = ""
var body: some View {
VStack {
Text("Authors").font(.title)
HStack {
List(authors, id: \.self, selection: $selectedAuthor) {author in
Text(author).tag(author)
}
Spacer()
}
}
}
但由于“无法推断通用参数'SelectionValue'”错误,我无法编译。我在这里做错了什么?我的目标是让选定的作者供以后使用。 谢谢。
【问题讨论】: