title: Load a nib file to act as a custom keyboard when a UITextField is tapped
body: <p>I'm trying to load a <code>.xib</code> file to act as a custom keyboard when a textField is tapped. I'm able to show the <code>.xib</code> file (view) when the textField is tapped but I'm not sure how to communicate the buttons in the <code>.xib</code> file with the a textField in the <em>ViewController.swift</em>. </p>
  
  <p>This is what I have done so far. </p>
  
  <ol>
  <li><p>Created a single project. </p></li>
  <li><p>Added a <code>UITextField</code> and created an outlet for it.</p>
  
  <pre><code>@IBOutlet weak var myField: MyTextField!
  </code></pre></li>
  <li><p>Created a new <code>.xib</code> file and called it <code>CustomView.xib</code>.</p></li>
  <li><p>Created a new class and called it <code>CustomView.swift</code>.</p></li>
  <li><p>Assigned class <code>CustomView.swift</code> to the <code>CustomView.xib</code> file. </p></li>
  <li><p>Added some <code>UIButtons</code> in the <code>CustomView.xib</code> file. These will be acting as a custom-keyboard, they will show when the textField is tapped and hide when the <code>resignFirstResponder</code> method is called.</p></li>
  <li><p>In the <code>viewDidLoad</code> method of the <code>ViewController.swift</code> I assigned <code>inputView</code> as follow. </p>
  
  <pre><code> import UIKit
  
   class ViewController: UIViewController {
  
    @IBOutlet weak var myField: MyTextField!
  
    override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
      let myView = NSBundle.mainBundle().loadNibNamed("CustomView", owner: self, options: nil).first as? CustomView
      myField.inputView = myView
      }
  }
  </code></pre></li>
  <li><p>Done</p></li>
  </ol>
  
  <p>When I run the app and tap on the textField the .xib file shows (see picture below), my problem is, how do I communicate the buttons with the textField in the <code>ViewController.swif</code>. In other words what I want is to show the numbers in the inputField when they are tapped.</p>
  
  <p>Any suggestions? Is this how this is usually done. </p>
  
  <p>Here is an image that shows the view shown when the inputField was tapped.</p>
  
  <p><a href="https://i.stack.imgur.com/lkCKi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lkCKi.png" alt="enter image description here"></a></p>