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 994353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:33:43+00:00 2026-05-16T06:33:43+00:00

Alright, I’ll try to explain this the best I can. I have an iPhone

  • 0

Alright, I’ll try to explain this the best I can. I have an iPhone app and it has a text field which the user can only input Numbers. Not a problem there. However, there is no done button on the numpad, so I can’t make it disappear. I could make a button that the user presses to dismiss the keyboard, but I’d rather have a done button because the screen is “busy” as is.

Well, after some research, I came across this. Wow, that worked great. However, I also have another text field which requires the default keyboard. And whenever the keyboard comes up, regardless of the type, it has the “Done” button on it.

Not good.

So I do some more digging. Read through the comments, and people mentioned a way to get rid of the Done button using the “Editing Did Begin” trait, to only call the “Done Button” code when necessary. I also got that mostly done. If you type in the number field, and then dismiss the keyboard, and then type in the normal field, the done button does not appear.

However, there is one bug, where the “Done” button still appears. If you tap the Numeric Field, and then tap the Normal field, the keyboard never “disappears”, so even though it changes from a numpad to a normal keyboard, the button still is there. I want to remove the buttom from the view, but I’m not sure how to go about this. This is the code I have…

//Done button for numpad
- (void)keyboardWillShow:(NSNotification *)note {
    if (showDoneButton == YES)
    {   


    // create custom button
    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];

    // 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 view found; add the custom button to it
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
            [keyboard addSubview:doneButton];
    }
        showDoneButton = NO; //This tells done button code to run or not
    }
}

- (void)doneButton:(id)sender {
    NSLog(@"Input: %@", playerOneLifeLabel.text);
    NSLog(@"Input: %@", playerTwoLifeLabel.text);
    [playerOneLifeLabel resignFirstResponder];
    [playerTwoLifeLabel resignFirstResponder];
}

When the NumPadfield triggers “editing did begin” it calls this function:

- (IBAction)needNumberPad:(id)sender{
    showDoneButton = YES;
}

Which then makes sure the done button is shown. When the done button code is done, the variable (as seen above) is set back to NO, so it doesn’t show up again if you tap the default text field. The Boolean variable is set to NO as default.

What needs to happen is if you jump immediately from editing the numPad field to the default field, the done button disappears. I can put the code in the function that is called when “Editing did end” but I don’t know what to put there. Help would be appreciated, I’ve gotten this far!

Thank you!

  • 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-16T06:33:43+00:00Added an answer on May 16, 2026 at 6:33 am

    Follow these steps

    a. First make the doneButton an instance varible of your class, this will help you maintain the reference to the button

    b. Add this code at the beginning of your keyboardWillShow:(NSNotification *)note method

    if(!showDoneButton ){
          if(doneButton){
    [doneButton removeFromSuperview];
    doneButton = nil;
          }
          return;
     }
    

    c. add notification for keyBoardWillHide

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(keyboardWillHide:) 
                                                 name:UIKeyboardWillHideNotification 
                                               object:nil];
    

    d. in keyBoardWillHide method do the following

    - (void)keyboardWillHide:(NSNotification *)note 
    {
    if(doneButton)
    {
        [doneButton removeFromSuperview];
        doneButton = nil;
    }
    }
    

    This should do the trick.

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

Sidebar

Related Questions

Alright so I have no idea how to even begin doing this But basically
Alright, I'll try and make this brief as possible. I wanted to a UIToolbar
Alright, i have read many different views on how to do this with no
Alright so this is a bizarre cross platform thing that I'm experiencing with text
Alright, I have some questions... When you have a moment, can you take a
Alright. This may be difficult but I have been struggling for quite a bit
Alright, this problem seems to be way above my head! I have this code:
Alright I have the MYSQL query code setup to pull this information out of
Alright, this is about the tenth time this has happened to me. I bumped
Alright it has come to this. I searched this website among many others and

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.