My problem: I tap in one of the TextFields
defined below and try to type. After typing a single character, the cursor disappears from the TextField
and I need to tap in the field again to enter the next character.
I have the following code:
@Observable
final class Species {
. . .
public var list: [String]
. . .
}
struct SpeciesCapture: View {
@State private var species = Species()
@State var trainingList: [String] = []
var body: some View {
NavigationStack {
VStack(alignment: .leading) {
HStack {
Text("some text")
Spacer()
Button("Add") {
trainingList.append("")
}
}
List {
ForEach($trainingList, id: \.self) { $animal in
TextField("Animal", text: $animal)
.textCase(.lowercase)
}
}
}
.onAppear {
trainingList = species.list
. . .
}
. . . // etc.
}
}
}
It appears that I am continually losing focus. How do I fix this problem?
Xcode 16.0 targeting iOS 18. The behavior appears in both Preview and the Simulator. (Haven't tried it on a physical device).