gpt4 book ai didi

ios - SwiftUI:无法推断通用参数 'C0'

转载 作者:行者123 更新时间:2023-12-01 18:35:48 25 4
gpt4 key购买 nike

我一直在使用此代码,但一直收到此错误:''无法推断通用参数'C0''' 此外,它在我的 HStack 上显示'调用函数'buildBlock' (SwiftUI.ViewBuilder)'当我包含这行代码时:

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
}
}
}

最佳答案

删除以下行 - body 中不允许 View 生成器

self.userData.tempBatchUnit = productName

我认为它应该在 .onCommit
    TextField("Enter here", text: $productName, onCommit: {
self.userData.tempBatchUnit = self.productName
})
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
.padding(.leading)

关于ios - SwiftUI:无法推断通用参数 'C0',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59652293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com