There seems to be no built-in mechanism for this, as other defendants have pointed out. As Nick says, you donβt need a complicated delegation template for this. Rather, you use the delegate template, but you get the delegate class for free. In this case, this is the UITextInput protocol.
So your keyboard probably looks like this (and has a NIB)
@interface ViewController : UIViewController // use assign if < iOS 5 @property (nonatomic, weak) IBOutlet id <UITextInput> *delegate; @end
When you create a keyboard controller, you assign it a UITextInput connector, something like this:
- (void)viewDidLoad { [super viewDidLoad]; HexKeyboardController *keyboardController = [[HexKeyboardController alloc] initWithNibName:@"HexKeyboardController" bundle:nil]; self.textField.inputView = keyboardController.view; keyboardController.delegate = self.textField; }
However, I thought that there MUST be a way to detect this keyboard only once and make the keyboard "automatically know" who called its UITextInput object. But I looked around to no avail ... you cannot understand who the firstResponder is unless you troll the view hierarchy yourself or save your delegates in a list (which will cause a save loop). Also, this is not so bad because the HexKeyboardController is also unloaded when the textField freed.
Dan rosenstark
source share