Hi, I'm using the trick to put a custom button for the numeric keyboard.
But I can't remove the button after use it, so in regular keyboard appear on top of the view.
This is how I add it:
- (void)keyboardShow:(NSValue *)v
{
if (isKeyboardNumeric) {
// create custom button
UIButton *doneButton = [[UIButton alloc] init];
//doneButton.buttonType = UIButtonTypeCustom;
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
if ([[[UIDevice currentDevice] systemVersion] hasPrefix:@"3"]) {
[doneButton setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
} else {
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
}
[doneButton addTarget:self action:@selector(dismissKeyboard:) forControlEvents:UIControlEventTouchUpInside];
doneButton.tag = 99;
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}
And this how I remove it:
- (void)keyboardHide
{
UIView *btn;
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {
for (btn in keyboard.subviews) {
if (btn.tag==99) {
[btn removeFromSuperview];
[btn release];
break;
}
}
}
}
[self setupButtons];
}
Both methods get called correctly, and in the debugger I confirm that is called
[btn removeFromSuperview]
But anyway, the button remain.
I try to put the code to remove it just before the if (isKeyboardNumeric)
call but nothing.