【发布时间】:2019-07-21 17:57:14
【问题描述】:
我正在尝试使用 TextField 来更改 CoreData 属性的数据,但我想出的一切都没有成功。有一个类似的问题(如下所列),我将把正确答案的代码贴出来解释一下。
struct ItemDetail: View {
@EnvironmentObject var itemStore: ItemStore
let idx: Int
var body: some View {
NavigationView {
Stepper(value: $itemStore.items[idx].inventory) {
Text("Inventory is \(self.itemStore.items[idx].inventory)")
}
// Here I would like to do this
// TextField("PlaceHolder", $itemStore.items[idx].name)
// That doesn't work... also tried
// TextField("PlaceHolder", $name) - where name is a @State String
// How can you then automaticlly assign the new value of @State name
// To $itemStore.items[idx].name?
.padding()
.navigationBarTitle(itemStore.items[idx].name)
}
}
}
原问题:
【问题讨论】: