3

I have a simple TextField in a HStack together with a button

 HStack { TextField("Level Name", text: $levelName) .font(.title) .padding(10) .background( RoundedRectangle(cornerRadius: 15) .strokeBorder(Color.primary.opacity(0.5), lineWidth: 3)) Button(action: { }) { Text("Submit").font(.title) } } 

Clicking on the textfield does not display the keyboard on my emulator, giving the console warning:

[LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x600002bba8f0 h=--& v=--& _UIButtonBarButton:0x7fdbcbc52e90.height == 0 (active)>", "<NSLayoutConstraint:0x600002bb4050 _UIUCBKBSelectionBackground:0x7fdbcbc53890.bottom == _UIButtonBarButton:0x7fdbcbc52e90.bottom - 6 (active)>", "<NSLayoutConstraint:0x600002bbff70 V:|-(6)-[_UIUCBKBSelectionBackground:0x7fdbcbc53890] (active, names: '|':_UIButtonBarButton:0x7fdbcbc52e90 )>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002bb4050 _UIUCBKBSelectionBackground:0x7fdbcbc53890.bottom == _UIButtonBarButton:0x7fdbcbc52e90.bottom - 6 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

4
  • would u add other relevant code too? Commented Jan 31, 2021 at 2:09
  • 1
    Running that in the simulator (14.3) Xcode 12.3 gives me the same warnings, but the keyboard still appears. Do you have "Connect Hardware Keyboard" checked in the Device menu of the simulator? Commented Jan 31, 2021 at 4:08
  • I set up a simple project and the code provided is the exact contents inside ContentView.swift. Where can I go to check the option? Commented Jan 31, 2021 at 4:39
  • @don In the Simulator go to: "I/O" => "Keyboard" => "Toggle Software Keyboard" Commented Jan 31, 2021 at 14:54

1 Answer 1

0

Your code works. Keyboard shows up. Running iOS 15.1.

struct TestView: View { @State var levelName = "" var body: some View { HStack { TextField("Level Name", text: $levelName) .font(.title) .padding(10) .background( RoundedRectangle(cornerRadius: 15) .strokeBorder(Color.primary.opacity(0.5), lineWidth: 3)) Button(action: { }) { Text("Submit").font(.title) } } } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.