SwiftUI : Why is my keyboard not showing?

I have a textfield set in a VStack. Everything is as it should be except that the keyboard is no longer showing up. Where did I mess up? How can I get the keyboard to show again?


return VStack {
                Image("food")
                    .resizable()
                    .aspectRatio(1.0, contentMode: .fit)
                    .clipShape(RoundedRectangle(cornerRadius: 50))
                    .gesture(longPressDrag)
                    .padding()
                    .offset(y: kGuardian.slide).animation(.basic(duration: 1.5))
                    .shadow(color: Color.black, radius: 15, x: 2, y: 2)
                TextField("Leave a comment", text: $comment, onEditingChanged: { if $0 { self.kGuardian.showField = 0 } }) {
                    commentText = self.comment
                }
                    .padding()
                    .background(GeometryGetter(rect: $kGuardian.rects[0]))
                    .background(Color(red: 239.0/255.0, green: 243.0/255.0, blue: 244.0/255.0, opacity: 1.0), cornerRadius: 10.0)
        }
            .padding()
            .shadow(color: Color.black, radius: 15, x: 2, y: 2)
            .offset(
                    x: viewState.width + dragState.translation.width
            )
            .presentation($showAlert) {
                Alert(title: Text("User commented on this photo!"), message: Text(commentText), primaryButton: .default(Text("OK")) {
                    commentText = ""
                    self.comment = ""
                    }, secondaryButton: .cancel()
                )
            }
Answered by Claude31 in 371236022

Not showing on device or in simulator ?


If in simulator, look in Hardware > Keyboard menu for the correct setting.

Accepted Answer

Not showing on device or in simulator ?


If in simulator, look in Hardware > Keyboard menu for the correct setting.

Thanks. I knew it had to be something simple and totally obvious.

and if on device its not showing?

With the Simulator App open, navigate to the menu bar and select I/O > Keyboard, then uncheck "Connect Hardware Keyboard".

SwiftUI : Why is my keyboard not showing?
 
 
Q