Question

I have a UIViewController with a UITextField that uses a custom 'DONE' button when the keyboardType is set to NumberPad. I've used code similar to this -

http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key

However, My problem is that the custom keyboard remains everywhere in other UIviews of application. If I call the keyboard from another View Controller I still get the 'DONE' button overlaying the keyboard. I have other views that need Uncustomized versions of the UIKeyboard.

Thanks

Was it helpful?

Solution

I started with the exact same blog as you mentioned above. I ran into the same exact issue because I had multiple keyboard types throughout my application.

My solution included these changes:

1 - Make the UIButton *doneButton a member variable for the Controller class

2 - In the "viewDidLoad" method, I have the following snippet

self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

3 - In the "doneButton" IBAction, I have the following snippet to make sure the button is removed from the keyboard view.

- (IBAction) doneButton:(id)sender {
    [self.view endEditing:YES];
    [doneButton removeFromSuperview];
}

The logic to add the button is no different than the blog describes so as long as you follow that direction, you should see the button on your number keyboard, then see it removed when you click the "DONE" button.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top