I'm new to iOS programming. I'm developing a custom keyboard with a custom nib file for it's view. How can I add target for buttons in the nib file without connect them manually to my UIInputViewController? I tried this code but doesn't works!
class LatinKeyboard: UIInputViewController {
override func viewDidLoad() {
super.viewDidLoad();
let nib = UINib(nibName: "KeyboardView", bundle: nil);
let objects = nib.instantiateWithOwner(self, options: nil)
view = objects[0] as UIView;
for subview in view.subviews {
if(subview is UIButton){
var key = subview as UIButton;
key.addTarget(self, action: "keyPressed:", forControlEvents: .TouchUpInside);
}
}
}
func keyPressed(sender: AnyObject?) {
let button = sender as UIButton
let title = button.titleForState(.Normal)
(textDocumentProxy as UIKeyInput).insertText(title!)
}
}