I have created a custom keyboard, using some buttons. I created them using interface builder, and I create a CustomKeyboardView
file..
So I have 3 files
- CustomKeyboardView.h
- CustomKeyboardView.m
- CustomKeyboardView.xib
I am adding this view to my UIViewController
like this
-(void)createCustomKeyboard{
//kbdCustom is an instance of CustomKeyboardView
kbdCustom = [[[NSBundle mainBundle] loadNibNamed:@"CustomKeyBoardView"
owner:self options:nil] objectAtIndex:0];
kbdCustom.delegate = self;
CGRect frame = kbdCustom.frame;
frame.origin.x = 14.0;
frame.origin.y = 300.0;
kbdCustom.frame = frame;
kbdCustom.backgroundColor = [UIColor clearColor];
[self.view addSubview:kbdCustom];
[self.view bringSubviewToFront:kbdCustom];
}
I am seeing the custom keyboard on my screen. But I couldn't touch in any of the button.
Nothing fancy in CustomKeyBoardView.m
file. I have some button handlers to address each different types of buttons in keyboard.
CustomKeyboardView.m
@implementation CustomKeyBoardView
- (IBAction)numberPressed:(id)sender {
NSLog(@"Number pressed");
}
- (IBAction)specialCharsPressed:(id)sender {
NSLog(@"specialCharsPressed");
}
- (IBAction)clearTextPressed:(id)sender {
NSLog(@"clearTextPressed");
}
- (IBAction)enterButtonPressed:(id)sender {
NSLog(@"enterButtonPressed");
}
@end
Some other points that might help you (to help me)
- I checked and rechecked the button handlers. They are wired to the
IBAction
. - I added a button programatically to the keyboard (Done it by
overriding
awakeFromNib
function inCustomKeyboardView.m
) and this button is also shown when I add it toUIViewController
. But no userInteraction on that button too. - The
UIViewController
in question is shown in aUIPopOverController
. And we use storyboard in our project. I have done added some log to see whether user interaction is enabled in
kbdCustom
and its super view. Answer was in the affirmativeNSLog(@"kbdCustom.userInteractionEnabled : %d" , kbdCustom.userInteractionEnabled); NSLog(@"superView.userInteractionEnabled : %d" , kbdCustom.superView.userInteractionEnabled);
its output is
kbdCustom.userInteractionEnabled : 1 superView.userInteractionEnabled : 1
And off course, user interaction on all the button is
YES
, and all of them are enabled in interface builder.I have adjusted the frame of the keyboard, to move it up over the UITextField( which is receiving touch events correctly). Now when I click on the keyboard buttons, the UITextField below it is getting touches, as if the keyboard is not there.