【发布时间】:2020-10-23 06:07:25
【问题描述】:
基本上我想要做的是如果你按下按钮然后条目应该得到一个新的 CEntry。如果有人可以帮助我,那就太好了。谢谢!
struct AView: View {
var entries = [CEntries]()
var body: some View {
ZStack {
VStack {
Text("Hello")
ScrollView{
ForEach(entries) { entry in
VStack{
Text(entry.string1)
Text(entry.string2)
}
}
}
}
Button(action: {
self.entries.append(CEntries(string1: "he", string2: "lp")) <-- Error
}) {
someButtonStyle()
}
}
}
}
C 类条目
class CEntries: ObservableObject, Identifiable{
@Published var string1 = ""
@Published var string2 = ""
init(string1: String, string2: String) {
self.string1 = string1
self.string2 = string2
}
}
【问题讨论】: