考虑建立以下机构(它不是试亮的显示,而是我认为能够复制我的问题的最快方式):
class IdentifiableString: Identifiable, Hashable {
static func ==(lhs: IdentifiableString, rhs: IdentifiableString) -> Bool {
lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(self.id)
}
let id = UUID()
var string = ""
}
struct ContentView: View {
@State var textField1Text = ""
@State var textField2Text = ""
@State var textField3Text = ""
@State var textField4Text = ""
@State var textField5Text = ""
@State var textField6Text = ""
@State var textField7Text = ""
@State var textField8Text = ""
@State var textField9Text = ""
@State var textField10Text = ""
@State var textField11Text = ""
@State var textField12Text = ""
@State var textField13Text = ""
@State var textField14Text = ""
@State var textField15Text = ""
@State var identifibleStrings = [IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString(), IdentifiableString()]
var body: some View {
List {
Button("Reset", role: .destructive) {
textField1Text = ""
textField2Text = ""
textField3Text = ""
textField4Text = ""
textField5Text = ""
textField6Text = ""
textField7Text = ""
textField8Text = ""
textField9Text = ""
textField10Text = ""
textField11Text = ""
textField12Text = ""
textField13Text = ""
textField14Text = ""
textField15Text = ""
for identifibleString in identifibleStrings {
identifibleString.string = ""
}
}
Section {
TextField("TextField 1", text: $textField1Text)
.onChange(of: textField1Text) { _, newValue in
identifibleStrings[0].string = newValue
}
TextField("TextField 2", text: $textField2Text)
.onChange(of: textField2Text) { _, newValue in
identifibleStrings[1].string = newValue
}
TextField("TextField 3", text: $textField3Text)
.onChange(of: textField3Text) { _, newValue in
identifibleStrings[2].string = newValue
}
TextField("TextField 4", text: $textField4Text)
.onChange(of: textField4Text) { _, newValue in
identifibleStrings[3].string = newValue
}
TextField("TextField 5", text: $textField5Text)
.onChange(of: textField5Text) { _, newValue in
identifibleStrings[4].string = newValue
}
TextField("TextField 6", text: $textField6Text)
.onChange(of: textField6Text) { _, newValue in
identifibleStrings[5].string = newValue
}
TextField("TextField 7", text: $textField7Text)
.onChange(of: textField7Text) { _, newValue in
identifibleStrings[6].string = newValue
}
TextField("TextField 8", text: $textField8Text)
.onChange(of: textField8Text) { _, newValue in
identifibleStrings[7].string = newValue
}
TextField("TextField 9", text: $textField9Text)
.onChange(of: textField9Text) { _, newValue in
identifibleStrings[8].string = newValue
}
TextField("TextField 10", text: $textField10Text)
.onChange(of: textField10Text) { _, newValue in
identifibleStrings[9].string = newValue
}
TextField("TextField 11", text: $textField11Text)
.onChange(of: textField11Text) { _, newValue in
identifibleStrings[10].string = newValue
}
TextField("TextField 12", text: $textField12Text)
.onChange(of: textField12Text) { _, newValue in
identifibleStrings[11].string = newValue
}
TextField("TextField 13", text: $textField13Text)
.onChange(of: textField13Text) { _, newValue in
identifibleStrings[12].string = newValue
}
TextField("TextField 14", text: $textField14Text)
.onChange(of: textField14Text) { _, newValue in
identifibleStrings[13].string = newValue
}
TextField("TextField 15", text: $textField15Text)
.onChange(of: textField15Text) { _, newValue in
identifibleStrings[14].string = newValue
}
}
Section {
VStack {
ForEach(identifibleStrings) { identifiableString in
if identifiableString.string != "" {
Text(identifiableString.string)
}
}
}
}
}
}
}
I ve discovered that when I provide all of my text fields with some kind of input, tap on the reset button, and then scroll down to my VStack
, I see this:
我发现,只有我把我的“五世纪之四”字 screen倒,我才发现,它已经适当调整了:
注: 如果在重新构造的纽芬兰语(,例如评论案文领域10-15,或用大屏幕(如iPad)操作有关装置的代码,在德国马克角上看到VStack的浏览量,那么这种行为就会出现。
我有时甚至没有足够增长才能适当展示其所有内容,但我没有能够一贯地重复这一行为。 我试图这样做,创建了一个“带有高米数据”的纽芬兰语,自动把我的所有文本领域都包含在数据上,但VStack却达到了预期的规模。
我试图在一次 <日/日/日/日/日/日/日/日/日/日/日/。 仅允许 < VVStack
@State var resetUpdate = false
Button("Set with Dummy Data") {
resetUpdate = true
...
}
.onChange(of: resetUpdate) { _, newValue in
if newValue == true {
resetUpdate = false
}
}
if !resetUpdate {
VStack {
...
但这没有效果。 可在以下网站查阅:http://www.un.org/Depts/DGACM/index_french.htm。 是否有人对这种行为发生的原因(以及如何防止这种行为)有任何怀疑?