You have accepted UIKeyInput in the UIViewController . Note the definition of inheritance introduced:
@interface Pedal_ProtocolViewController : UIViewController <UIKeyInput, UITextInput>{
You said here: "This is a view controller that implements UIKeyInput and UITextInput ." These two protocols apply to subclasses of UIResponder , such as UIView and subclasses or UIView . UIViewController not one such class , it may not be the best class for handling text input.
View controllers for managing views. They themselves are not species.
You can (instead of text input protocols) just use a hidden text field (for example, the one you already have). Just create a subclass of NSObject that implements a delegate for the text field and assigns it as a delegate to the text field. Then in -viewDidAppear: call -becomeFirstResponder in the text box to focus on the box. Perhaps you can use some hacks to hide the keyboard.
This approach has been widely used in games and gaming libraries to display a software keyboard. It even works on iOS 3.1.3 and earlier (which is not a problem for you, considering what you are developing for the iPad).
If you save this construct (by processing the input in the view controller), this may be required and make it work.
-(BOOL)canBecomeFirstResponder { return YES; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self becomeFirstResponder]; }
Consider using a UITextField and a delegate to handle input or implement the above two functions and the UIKeyInput protocol in a subclass of UIView .
Also note that you do not need to match a UITextInput just for receiving keystrokes; UIKeyInput enough.
Additional note: if you decided to subclass UIView (which, along with using the hidden UITextField , is what I am doing, I have not tried subclassing the UIViewController to get keyboard input), you will want to add -becomeFirstResponder to -awakeFromNib instead:
-(void)awakeFromNib { [super awakeFromNib]; [self becomeFirstResponder]; }
This is if you download the UIViewController (and therefore the UIView ) from nib. Not this way? Try adding that to -initWithFrame: ::
-(id)initWithFrame:(CGFrame)frame { self = [super initWithFrame:frame]; if(!self) return nil; [self becomeFirstResponder]; return self; }
Alternatively, in the UIViewController viewDidLoad :
// ... [self.view becomeFirstResponder]; // ...
Here it is obvious that you can do it.;)