Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7494241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:24:18+00:00 2026-05-29T17:24:18+00:00

I’m trying to hide the number pad, but I do not want to implement

  • 0

I’m trying to hide the number pad, but I do not want to implement a button.

Is there a way to dismiss the number pad when the user taps outside the textfield?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:24:22+00:00Added an answer on May 29, 2026 at 5:24 pm

    This is one of those questions where you read it and say “That’s easy you just..”. And then you go to do it and make it super complicated. And then realize it doesn’t have to be that complicated.

    The answer I’ve come up with, and I’m sure it will help someone else, Is to use an invisible UIView that never interacts but acts on other views and maybe not in the way you’d think.

    The typical answer to a question about dismissing the UIKeyboardTypeNumberPad keyboard is to add a bar that has a button as the inputAccessoryView to dismiss the keyboard. If a bar and button are undesirable generally you just listen for touch events on the background and your good to go but this question is about a tableview and that makes this much harder.

    But this inputAccessoryView feature is still awesome. It allows you to define a UIView or UIView subclass to be displayed when the keyboard is shown. More importantly when the keyboard is shown due to a textfield for which it is the inputAccessoryView becoming first responder.

    I could yammer on but first here is some code for a lightweight class that actually performs very well in testing.

    The contents of NJ_KeyboardDismisser.h are:

    #import <UIKit/UIKit.h>
    
        // For some reason neither inputView or inputAccessoryView are IBOutlets, so we cheat.
    @interface UITextField (WhyDoIHaveToDoThisApple)
    @property (readwrite, retain) IBOutlet UIView *inputAccessoryView;
    @end
    
    @interface NJ_KeyboardDismisser : UIView
    @property (nonatomic, weak) IBOutlet UIView *mainView;
    -(id)initWithMainView:(UIView *)view; // convienience method for code
    @end
    

    And the contents of NJ_KeyboardDismisser.m are:

    #import "NJ_KeyboardDismisser.h"
    @implementation NJ_KeyboardDismisser {
        UITapGestureRecognizer *_tapGR;
    }
    @synthesize mainView = _mainView;
    -(void)setMainView:(UIView *)view{
        if (_tapGR) [_tapGR.view removeGestureRecognizer:_tapGR];
        _mainView = view;
        _tapGR = [[UITapGestureRecognizer alloc] initWithTarget:_mainView action:@selector(endEditing:)];
    }
    -(id)initWithMainView:(UIView *)view{
        if ((self = [super initWithFrame:CGRectMake(0, 0, 0, 0)])){
            self.mainView = view;
        }
        return self;
    }
    -(void)didMoveToWindow{ // When the accessory view presents this delegate method will be called
        [super didMoveToWindow];
        if (self.window){ // If there is a window one of the textfields, for which this view is inputAccessoryView, is first responder.
            [self.mainView addGestureRecognizer:_tapGR];
        }
        else { // If there is no window the textfield is no longer first responder
            [self.mainView removeGestureRecognizer:_tapGR];
        }
    }
    @end
    

    You may recognize the endEditing: method, as mentioned by Cosique, it is a UIView extension method that asks a views nested textfield to resign. Sound handy? It is. By calling it on the tableview the textfield it contains resigns first responder. Since this technique works on all UIViews there is no need to artificially limit this outlet to only UITableViews so the outlet is just UIView *mainView.

    The final moving part here is the UITapGestureRecognizer. We don’t want to add this recognizer full time for fear of screwing up the tableview’s workings. So we take advantage of UIView‘s delegate method didMoveToWindow. We don’t really do anything with the window we just check to see if we are in one; If we are then one of our textfields is first responder, if not then it’s not. We add and remove our gesture recognizer accordingly.

    Okay straightforward enough, but how do you use it? Well if instantiating in code you could do it like this, in tableView:cellForRowAtIndexPath::

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
        UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(20, 6, 100, 31)];
        [cell.contentView addSubview:field];
        field.keyboardType = UIKeyboardTypeNumberPad;
        field.inputAccessoryView = [[NJ_KeyboardDismisser alloc] initWithMainView:self.view];
    }
    

    If you are using static cells in a storyboard then the technique is different (obviously). First drag out a generic NSObject and place it in the dark grey strip below the view (where the other objects such as the view controller are). Then change this new object’s class to be NJ_KeyboardDismisser. Then connect the “Keyboard Dismisser”‘s mainView property to that view (generally a tableview). Then connect the inputAccessoryView property from any each text field in that scene you wish to the “Keyboard Dismisser”.

    Image of the Keyboard Dismisser object listed among the other view controller objects.

    Give it a try! The tableview acts normally. Apple’s tap recognizer is smart enough to ignore the swipes on the table, so you can scroll. It also ignores touches in the textfields so you can edit and select other textfields. But tap outside a textfield and the keyboard is gone.

    Note: This class’s use is not limited to tableviews. If you want to use it on a regular view, just set the mainView property to be the same as the view controller’s view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.