Reputation: 77
Following this thread (& others)
A Swift example of Custom Views for Data Input (custom in-app keyboard)
I've built a custom input view from a nib in an app.
However, I would like to implement it within a custom keyboard extension. I would like to let users search for content directly within the custom keyboard.
Not sure if it has something to do with the responder chain or UIInputViewController vs UIViewController or what.
Here is the KeyboardViewController, will post more if needed. Any suggestions would be great.
The Keyboard build fine, but when I click into the UITextField, nothing happens. The cursor starts flashing, but the nib never shows up.
import UIKit
class KeyboardViewController: UIInputViewController, KeyboardDelegate {
@IBOutlet weak var textField: UITextField!
@IBOutlet var nextKeyboardButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
let keyboardView = Keyboard(frame: CGRect(x: 0, y: 0, width: 0, height: 300))
keyboardView.delegate = self // the view controller will be notified by the keyboard whenever a key is tapped
// replace system keyboard with custom keyboard
textField.inputView = keyboardView
}
// required method for keyboard delegate protocol
func keyWasTapped(character: String) {
textField.insertText(character)
}
func keyDone() {
view.endEditing(true)
}
func backspace() {
textField.deleteBackward()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated
}
}
Upvotes: 1
Views: 1813
Reputation: 2099
Are you testing on the simulator? If so when you are on the simulator press Command+K to trigger the soft keyboard. The Simulator doesn't flash the keyboard since it knows you have your real pc keyboard which is easier to use.
Hope this helps!
Upvotes: 0