3

I have a 3 TextFields in SwiftUI. one on top and two side by side underneath that.

VStack{
    //TF1
    TextField("Duty", text: $dutyNumber)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .padding([.leading], 50)
                            .multilineTextAlignment(.center)
                            .keyboardType(.numberPad)
    HStack{
        //TF2
        TextField("Start time", text: $dutyStartTime)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .padding([.leading], 50)
                            .multilineTextAlignment(.center)
                            .keyboardType(.numberPad)
        //TF3 
        TextField("Finish time", text: $dutyFinishTime)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .padding([.leading], 50)
                            .multilineTextAlignment(.center)
                            .keyboardType(.numberPad)
    }
}.cornerRadius(4)

However only the last textfield TF3 is interactive. Cannot select the first two TF1 & TF2. Can Tab into them with keyboard but cannot select them with a finger tap. If I change the order from TF1, TF2, TF3 to TF1, TF3, TF2 for example. Then TF2 is now interactive but TF1 & TF3 are not. Is this a bug with adding multiple TextFields in SwiftUI or am I missing something obvious?

3
  • Check out this link. It seems to have fixed the issue on simulator for me but I cant test it on a physical device since none of my devices are on iOS 13. Commented Aug 3, 2019 at 2:27
  • I tested on the real device and it works fine. On the simulator, the keyboard won't show initially, because it seems to default to software keyboard. By using CMD+K the keyboard shows up. Commented Aug 3, 2019 at 3:58
  • When change the VStack to a Form the Textfields are able to be interacted with but that's not the design I am after. Commented Aug 5, 2019 at 21:10

1 Answer 1

4

Adding answer to benefit others.

having played around with it the solution was to remove .cornerRadius and the all the TextFields work.

 VStack{
//TF1
    TextField("Duty", text: $dutyNumber)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .padding([.leading], 50)
                            .multilineTextAlignment(.center)
                            .keyboardType(.numberPad)

      HStack{
//TF2
    TextField("Start time", text: $dutyStartTime)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .padding([.leading], 50)
                            .multilineTextAlignment(.center)
                            .keyboardType(.numberPad)
//TF3 
    TextField("Finish time", text: $dutyFinishTime)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .padding([.leading], 50)
                            .multilineTextAlignment(.center)
                            .keyboardType(.numberPad)

        }
    }//.cornerRadius(4)
Sign up to request clarification or add additional context in comments.

2 Comments

But why it did fixed?
didn't work!! why Apple doesn't fix this stupid bug

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.