Action Button(Textfield)

Good day, I would like to generate a text field when I tap on the green button that creates a new text field and I can still enter for example a 2nd phone number. I have already tried it with this example:

Button(action: { print("Telefonnummer")}) {
          Image(systemName: "plus.circle.fill")
                .foregroundColor(Color(.systemGreen)) 
               }

Can 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.

struct heartTextSquareView: View {     @State private var name: String = ""     @State private var adresse: String = ""     @State var telefonnummer: String = ""     @State var something: String = ""     var body: some View {         VStack {             List {                 TextField("Name/Vorname", text: $name)                 TextField("Adresse", text: $adresse)                 Button(action: { print("Telefonnummer")}) {                                Image(systemName: "plus.circle.fill")                                     .foregroundColor(Color(.systemGreen))                 }             }

Sorry I didn't want that

struct heartTextSquareView: View {
    @State private var name: String = ""
    @State private var adresse: String = ""
    @State var telefonnummer: String = ""
    @State var something: String = ""
    var body: some View {
        VStack {
            List {
                TextField("Name/Vorname", text: $name)
                TextField("Adresse", text: $adresse)
                
                Button(action: { print("Telefonnummer")}) {
                               Image(systemName: "plus.circle.fill")
                                    .foregroundColor(Color(.systemGreen))

                }                

            }

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.

Then these problems will occur. And I don't understand why. Can someone help me?

Action Button(Textfield)
 
 
Q