【问题标题】:SwiftUI: Generic parameter 'C0' could not be inferredSwiftUI:无法推断通用参数“C0”
【发布时间】:2020-04-26 08:51:42
【问题描述】:

我一直在使用此代码,但一直收到此错误:“无法推断通用参数“C0””此外,它在我的HStack 当我包含这行代码时:

self.userData.tempBatchUnit = productName

我不知道为什么。没有那行代码,代码可以正常工作。非常感谢

struct enterProductUnitView: View {
    @EnvironmentObject var userData: UserData
    @State var productName: String = ""

    var body: some View {
        VStack {
            HStack { // error Generic parameter 'C0' could not be inferred
                Text("Product Unit:")
                    .font(.headline)
                Spacer()
                NavigationLink(destination: InstructionsView(desireInstructions: "Product Unit")) {
                    Text("?")
                }
            }

             Text("ex: bags of popcorn, jars of jam etc.")
                .font(.subheadline)
            TextField("Enter here", text: $productName)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .padding()
                .padding(.leading)
            self.userData.tempBatchUnit = productName
        }
    }
}

【问题讨论】:

    标签: ios swift swiftui


    【解决方案1】:

    删除以下行 - bodyview builder 中不允许这样做

    self.userData.tempBatchUnit = productName
    

    我认为它应该在.onCommit

        TextField("Enter here", text: $productName, onCommit: {
                self.userData.tempBatchUnit = self.productName
            })
            .textFieldStyle(RoundedBorderTextFieldStyle())
            .padding()
            .padding(.leading)
    

    【讨论】:

      猜你喜欢
      • 2020-04-19
      • 2022-08-17
      • 2019-12-16
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多