Overview
The IQKeyboardReturnManager subspec provides automatic return key handling, allowing users to navigate between text fields by pressing the Return key on the keyboard. The manager automatically changes the return key type to “Next” or “Done” based on the field’s position in the form.IQKeyboardReturnManager is now available as an independent library, similar to IQKeyboardToolbarManager.
Installation
CocoaPods
Podfile
Swift Package Manager
The IQKeyboardReturnManager is included in the main package or can be added separately:How It Works
The Return Key Manager automatically:- Detects text field order in your form
- Changes return key type to “Next” for fields with a next field
- Changes return key type to “Done” for the last field
- Handles return key taps to move to the next field or dismiss keyboard
- Works with UITextField and UITextView
Basic Setup
Return key handling works automatically once IQKeyboardManager is enabled:AppDelegate.swift
Return Key Types
The manager automatically sets appropriate return key types:Next
Used for fields that have a next text field in the form
Done
Used for the last text field to dismiss the keyboard
Navigation Flow
ViewController.swift
- Taps Return on
firstNameField→ moves tolastNameField - Taps Return on
lastNameField→ moves toemailField - Taps Return on
emailField→ moves topasswordField - Taps Return on
passwordField→ dismisses keyboard
Manual Return Key Control
You can still manually set return key types when needed:ViewController.swift
Manually set return key types will be respected by IQKeyboardManager.
Custom Return Key Actions
Implement UITextFieldDelegate to customize behavior:ViewController.swift
UITextView Support
For multi-line text views, the manager handles return keys intelligently:ViewController.swift
Handling Special Cases
Search Fields
ViewController.swift
Submit Forms
ViewController.swift
Disable Return Key Handling
If you want to disable automatic return key handling while keeping other IQKeyboardManager features:AppDelegate.swift
Return Key vs Toolbar Navigation
Return Key Navigation
Advantages:
- Natural typing flow
- No additional UI
- Familiar to users
- Works great for short forms
- Less discoverable
- No previous button
- Requires pressing return
Toolbar Navigation
Advantages:
- Visible Previous/Next/Done buttons
- Can go back to previous fields
- More discoverable
- Better for long forms
- Takes up space above keyboard
- Additional UI element
Combined Example
CompleteFormViewController.swift
Best Practices
Let the manager handle return keys automatically
Let the manager handle return keys automatically
Unless you have specific requirements, let IQKeyboardManager automatically configure return key types. It’s smart enough to handle most scenarios.
Use .search for search fields
Use .search for search fields
Set
returnKeyType = .search for search fields to show the search icon instead of “Next” or “Done”.Consider UX for multi-line text views
Consider UX for multi-line text views
For fields that need line breaks (like comments or notes), use
.default return key type. For single-line behavior, use .next or .done.Test the flow
Test the flow
Always test the complete navigation flow to ensure users can easily move through your form using the Return key.
Troubleshooting
Return key not advancing to next field
Return key not advancing to next field
- Verify IQKeyboardManager is enabled
- Check if you’ve implemented
textFieldShouldReturnthat returnsfalse - Ensure text fields are in the view hierarchy
- Check that next field is a valid text input view
Wrong return key type showing
Wrong return key type showing
- Check if you’ve manually set
returnKeyType - Verify the field order in your view hierarchy
- Try reloading the keyboard:
textField.reloadInputViews()
Return key dismissing keyboard unexpectedly
Return key dismissing keyboard unexpectedly
- Check if the field is detected as the last field
- Verify all text fields are properly connected
- Ensure hidden fields are actually visible when needed
Next Steps
Toolbar Management
Add Previous/Next/Done buttons for additional navigation
Resign Keyboard
Dismiss keyboard by tapping outside text fields
Advanced Configuration
Fine-tune keyboard behavior
Debugging
Troubleshoot return key issues