0

How I can disappear numeric keyboard in iPhone because there is no return key in it, which implies it is not going to respond to

- (BOOL)textFieldShouldReturn:(UITextField *)textField
itsaboutcode
  • 24,525
  • 45
  • 110
  • 156
  • Duplicate of: - - - - - - - - And that was just on the first page of search results... – Dave DeLong Sep 10 '09 at 22:54
  • 1
    I am afraid you are wrong because they all are talking about when Keyboard is not of Numeric Type, I know how to disable the keyboard when its not numeric, its different case, when you have to disappear "NUMERIC Keyboard". And i search before putting that question. – itsaboutcode Sep 10 '09 at 22:58
  • You can easily put a button on your screen to dismiss the keyboard once the user has entered the number. Isn't that how the phone app works? Or you could put a toolbar above the keyboard with a "don" button on it, or any number of things (automatically dismiss the keyboard after x seconds of inactivity, once the text in the field validates, etc etc) – Dave DeLong Sep 10 '09 at 23:11
  • [theTextField resignFirstResponder]; works no matter what keyboard you have. – Jordan Sep 11 '09 at 03:25
  • Dave you are a nice guy, but you are hooked on trying to find duplicate answers. You are really smart though. Can you look at this question. http://stackoverflow.com/questions/4360140/adding-done-button-to-only-number-pad-keyboard-on-iphone – Bryan Dec 05 '10 at 17:34
  • @Bryan and you seem to be a guy hooked on finding my answers that just list links to duplicate questions. I promise there are others (more than a thousand others, in fact). – Dave DeLong Dec 05 '10 at 21:31

5 Answers5

3

Use resignFirstResponder in touchesBegan, like so:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch * touch = [touches anyObject];
    if(touch.phase == UITouchPhaseBegan) {
        [self.myTextField resignFirstResponder];
    }
}

You may need to call this on multiple text fields if you're not sure where the focus is currently located; I haven't tested that case.

Additionally, in Interface Builder, you'll need to enable the "User Interaction Enabled" checkbox for the view, or programatically use:

myView.userInteractionEnabled = YES;
iUser
  • 330
  • 2
  • 8
2

Here's the answer..

-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event

{

    //[URL resignFirstResponder];

    //[Password resignFirstResponder];

    [speedField resignFirstResponder];

    [super touchesBegan:touches withEvent:event ];

}
ManjotSingh
  • 713
  • 7
  • 20
0

Try this:

[theTextField resignFirstResponder];
ennuikiller
  • 46,381
  • 14
  • 112
  • 137
0

Why not to use "Numbers and Punctuation" keyboard instead of "Numeric"? It will save your time

MikeR
  • 609
  • 6
  • 12
-2

Here you go. Extend your UIViewController Class with this. But how do we know it is the done button? Adding Done Button to Only Number Pad Keyboard on iPhone

//
//  UIViewController+NumPadReturn.m
//  iGenerateRandomNumbers
//
//  Created by  on 12/4/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "UIViewController+NumPadReturn.h"


@implementation UIViewController (NumPadReturn)

-(void) viewDidLoad{
    // add observer for the respective notifications (depending on the os version)
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(keyboardDidShow:) 
                                                     name:UIKeyboardDidShowNotification 
                                                   object:nil];     
    } else {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(keyboardWillShow:) 
                                                     name:UIKeyboardWillShowNotification 
                                                   object:nil];
    }

}


- (void)keyboardWillShow:(NSNotification *)note {
    // if clause is just an additional precaution, you could also dismiss it
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 3.2) {
        [self addButtonToKeyboard];
    }
}

- (void)keyboardDidShow:(NSNotification *)note {
    // if clause is just an additional precaution, you could also dismiss it
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
        [self addButtonToKeyboard];
    }
}

- (void)addButtonToKeyboard {
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0) {
        [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];
    // 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 found, add the button
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
            if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
                [keyboard addSubview:doneButton];
        } else {
            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
                [keyboard addSubview:doneButton];
        }
    }


}

- (void)doneButton:(id)sender {
    NSLog(@"doneButton");
    [self.view endEditing:TRUE];
}
Community
  • 1
  • 1
Bryan
  • 17,201
  • 24
  • 97
  • 123
  • 1
    -1 this is a total hack and shouldn't be used. What if apple decides to change the name of "UIKeyboard" to `UIKBView?` You should never rely on undocumented behavior or implementation details to make your code work properly. If you need behavior that's not possible without undocumented stuff, file a bug. – Dave DeLong Dec 05 '10 at 21:30