Why this happens
When you click inside a UITextField, UITextView, or SwiftUI TextField in the iOS Simulator, the system expects user input. By default, Xcode connects your Mac physical keyboard to the Simulator session. When this connection is active, iOS treats the simulator environment as an iPad or iPhone paired with an external Bluetooth keyboard.
Under standard iOS behavior, connecting an external hardware keyboard automatically suppresses the on-screen virtual keyboard to preserve display real estate. Because your Mac keyboard is transmitting keystrokes directly into the Simulator, iOS assumes an on-screen keyboard is unnecessary and hides it.
In other cases, the software keyboard fails to present because the underlying view has not successfully acquired first responder status. If text view focus is requested programmatically before the view hierarchy attaches to an active UIWindow, the responder chain ignores the request and the keyboard never initializes.
How to fix it
1. Toggle the Software Keyboard Using ⌘K
The fastest way to reveal the virtual keyboard without detaching your physical keyboard is to toggle it directly with the keyboard shortcut:
- Run your app in the Simulator.
- Click inside the text field or text view so the blinking cursor appears.
- Press Command + K (
⌘K) on your Mac keyboard.
The virtual software keyboard will slide up from the bottom of the simulator screen immediately. Pressing ⌘K a second time dismisses it.
2. Disconnect the Hardware Keyboard via the Simulator Menu
If you want the on-screen keyboard to appear automatically every time any text input field gains focus, disconnect your Mac physical keyboard from the simulator runtime:
- Click the Simulator window to make it the active application.
- In the macOS menu bar at the top of your screen, click I/O.
- Hover over Keyboard.
- Uncheck Connect Hardware Keyboard (shortcut: Shift + Command + K or
⇧⌘K).
(Note: In legacy Xcode versions prior to Xcode 9, this setting was located under Hardware > Keyboard > Connect Hardware Keyboard.)
Once unchecked, tapping any input field will automatically present the on-screen keyboard just like a physical device without an external accessory.
3. Ensure the View Becomes First Responder in Code
If the shortcuts do not show the keyboard, your text input field might not be receiving focus. In UIKit, calling becomeFirstResponder() too early—such as inside viewDidLoad()—fails silently because the view is not yet part of the active window hierarchy.
Move programmatic focus calls to viewDidAppear(_:):
import UIKit
final class LoginViewController: UIViewController {
@IBOutlet private weak var emailTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do not call becomeFirstResponder() here
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// The view hierarchy is attached to the window; safe to focus
emailTextField.becomeFirstResponder()
}
}
In SwiftUI, verify that your @FocusState property is bound correctly and triggered after the view appears:
import SwiftUI
struct LoginView: View {
@State private var email = ""
@FocusState private var isEmailFocused: Bool
var body: some View {
VStack {
TextField("Enter email", text: $email)
.textFieldStyle(.roundedBorder)
.focused($isEmailFocused)
.padding()
}
.onAppear {
// Delay focus slightly or bind directly after hierarchy settles
isEmailFocused = true
}
}
}
4. Erase Simulator Settings and Derived Data
If the Simulator becomes unresponsive or the I/O keyboard toggle remains greyed out despite active text focus, the Simulator daemon state may be corrupted:
- In the Simulator menu bar, click Device > Erase All Content and Settings….
- Confirm the prompt to reset the simulated device back to its factory state.
- In Xcode, clear the build cache by pressing Shift + Option + Command + K (
⇧⌥⌘K) or selecting Product > Clean Build Folder. - Re-run your project from Xcode.
How to prevent it
- Keep Connect Hardware Keyboard toggled on during typing tests: Leave hardware keyboard enabled for fast typing, and use
⌘Konly when you need to inspect keyboard layouts, toolbars, or accessory views. - Avoid early responder calls: Never call
becomeFirstResponder()in view initialization orviewDidLoad(). Always wait untilviewDidAppear(_:)or use SwiftUI’s@FocusState. - Check input accessory views: Ensure custom
inputAccessoryViewimplementations return valid layouts with non-zero heights so they do not collapse the keyboard layout container.
FAQ
Why does the keyboard disappear immediately after showing in the simulator?
This usually occurs when another view or gesture recognizer in your hierarchy cancels first responder status. Check whether you have a UITapGestureRecognizer with cancelsTouchesInView = true or logic inside textFieldDidBeginEditing that resigns first responder prematurely.
Can I type using both my Mac keyboard and see the software keyboard at the same time?
Yes. Keep Connect Hardware Keyboard checked under I/O > Keyboard, and press Command + K (⌘K). The on-screen software keyboard will stay visible while still accepting keystrokes from your Mac keyboard.
Why is “Toggle Software Keyboard” greyed out in the menu?
The menu item under I/O > Keyboard is disabled when no view in the currently running simulator app has first responder status. Click into an editable text field inside the app first to enable the option.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
