Please try something like this:
import SwiftUI
struct HeartTextSquareView: View {
@State private var name: String = ""
@State private var adresse: String = ""
@State var telefonnummern: [String] = [] //<-
@State var something: String = ""
var body: some View {
VStack {
List {
TextField("Name/Vorname", text: $name)
TextField("Adresse", text: $adresse)
ForEach($telefonnummern, id: \.self) {$telefonnummer in
TextField("Telefonnummer", text: $telefonnummer)
}
Button(action: {
telefonnummern.append("")
}) {
Image(systemName: "plus.circle.fill")
.foregroundColor(Color(.systemGreen))
}
}
} //End VStack
}//End body
}//End `HeartTextSquareView`
When you want variable number of UI elements, you need to prepare a variable each element of which represents each UI element.
-
—
OOPer
-
—
iRIG
-
—
OOPer
Add a CommentCan you clarify what you want to ask?
So if you tap on the plus button in the text field, I want it to create a new text field if you have several phone numbers, for example.
What I do not understand is that your code shown does not contain any TextField. You should better show more code even if it might not be perfect. That would explain what you want to do better than the too simple example.