SwiftUI-列表给出错误“表达式类型不明确,没有更多上下文”

时间:2019-09-23 13:12:34

标签: swiftui swiftui-list

我正在尝试实现具有多个选择的列表。

这是代码:

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

但是下面出现错误:

“在没有更多上下文的情况下,表达类型不明确”

enter image description here

感谢任何人都可以提供帮助! :)

1 个答案:

答案 0 :(得分:2)

问题在您的.mat-form-field-subscript-wrapper{ position: static; } .mat-form-field-underline{ position: static; } 初始化中。将其更改为List,其中包含List,如下所示:

ForEach