我正在尝试实现具有多项选择的列表。
这是代码:
import SwiftUI
struct MultiSelectionWithEditButton : View {
var items = ["One","Two", "Three"]
@State var selectedRows = Set<String>()
var body: some View {
NavigationView {
List((items, id: \.self), selection: $selectedRows) { name in
Text(name)
.font(.title)
.fontWeight(.bold)
}
.navigationBarItems(trailing: EditButton())
.navigationBarTitle(Text("Selected \(selectedRows.count) rows"))
}
}
}
#if DEBUG
struct MultiSelectionWithEditButton_Previews : PreviewProvider {
static var previews: some View {
MultiSelectionWithEditButton()
}
}
#endif
但我得到以下错误:
“没有更多上下文,表达的类型是模棱两可的”
感谢是否有人可以提供帮助!:)