Well, I will try to explain it as best as possible. I have an iPhone app and it has a text box that the user can only enter Numbers. No problem. However, there is no button on the numpad button, so I cannot make it disappear. I could make a button that the user presses to cancel the keyboard, but I would rather make a button because the screen is "busy" as it is.
Well, after some research, I came across this . Wow, that's great. However, I also have another text box that requires a default keyboard. And whenever the keyboard appears, regardless of type, it has a Finish button on it.
Not good.
So, I dig a little more. Read the comments, and people mentioned a way to get rid of the Done button, using the “Edit at the initial stage” property to call the “Done” code when necessary. I also got this mostly. If you enter a number field and then release the keyboard and then enter a normal field, the Finish button will not appear.
However, there is one error when the "Finish" button still appears. If you press the “Numeric field” and then touch the “Normal” field, the keyboard will never “disappear”, so even if it changes from a numeric keypad to a regular keyboard, the button is still present. I want to remove buttom from a view, but I'm not sure how to do it. This is the code I have ...
- (void)keyboardWillShow:(NSNotification *)note {
if (showDoneButton == YES)
{
UIButton *doneButton = [UIButton buttonWithType: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(doneButton:) forControlEvents:UIControlEventTouchUpInside];
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
showDoneButton = NO;
}
}
- (void)doneButton:(id)sender {
NSLog(@"Input: %@", playerOneLifeLabel.text);
NSLog(@"Input: %@", playerTwoLifeLabel.text);
[playerOneLifeLabel resignFirstResponder];
[playerTwoLifeLabel resignFirstResponder];
}
NumPadfield "", :
- (IBAction)needNumberPad:(id)sender{
showDoneButton = YES;
}
done. , ( ) NO, , . NO.
, numPad , done . , , " ", , . , !
!