1

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
    }



}
Ben Shaw
  • 77
  • 8

1 Answers1

0

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!

Mohamad Bachir Sidani
  • 2,077
  • 1
  • 11
  • 17
  • Thanks Mohammad, I'm using the soft keyboard and when I switch over to my custom keyboard, they keyboard with the UITextField is there, but when I click within the text field, then my custom nib never shows up. – Ben Shaw Dec 14 '17 at 12:48
  • When you do this you just close out the Keyboard Extension as that is the keyboard the sim thinks you are referring to, it doesn't affect the InputView inside the Keyboard Extension that Ben is trying to make appear. – David Villegas Jan 04 '20 at 00:48