Loading

Monday, January 3, 2011

UIKeyboardTypeNumberPad missing "return" key

I get the code from Google and modify it for DONE Button in UIKeyboardTypeNumberPad (works in iPhone 4 SDK)

- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField==txtZipCode)
{
[self setViewMovedUp:YES];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(keyboardDidShowOrHide:)
name: UIKeyboardDidShowNotification object:nil];

}
else
{

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
}



}
- (void) keyboardDidShowOrHide : (id) sender {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 427, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setBackgroundImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton setBackgroundImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
[tempWindow addSubview:doneButton];


}
-(void)doneButton:(id)sender
{
UIButton *btntmp=sender;
[btntmp removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
[self setViewMovedUp:NO];
[txtZipCode resignFirstResponder];
}

1 comment:

  1. my view have more 2 texfield than. How to add done button to "number pad" key board?

    I touch textfield1(UIKeyboardTypeNumberPad) it show "done" button
    then I touch textfield2 (Kerboard default) and I touch textfield1 but it don't show "done" button. Can you help me?

    ReplyDelete