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

  • Home
  • SEARCH
  • 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 800843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:21:04+00:00 2026-05-14T23:21:04+00:00

I have several uitextfields within a view and I would like to disable the

  • 0

I have several uitextfields within a view and I would like to disable the uibutton until all the fields have something entered into them. What’s the best way of doing this?
Ideally, I’d like to do some basic validation (make sure all entries are numbers) too.


EDIT

Couldn’t get the solutions below to quite work. Below is the version that I got working (cobbled together from Brad, Mike, and various other sources)

Use the UITextFieldDelegate

Create textfields in IB, and attach to the relevant IBOutlets – textField1, textField2 etc

Create and hookup the button to its relevant IBOutlet (submitButton) and IBAction (submitAction) in IB. Uncheck enabled in IB.

Create a validate method in the view controller:

-(IBAction)validateTextFields:(id)sender
    {
        // make sure all fields are have something in them
        if ((textField1.text.length  > 0) && (textField2.text.length > 0)  && (textField3.text.length > 0)) {
            self.submitButton.enabled = YES;
        }
        else {
            self.submitButton.enabled = NO;
        }
    }

Hookup each fields ‘Editing Changed’ event to the validateTextFields method. (Note: The ‘Value Changed’ event doesn’t appear to work)

Use this delegate method to limit characters (in my case to numbers, and up to one full-stop). This bit is from Erica Sadun btw.

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSCharacterSet *cs;
    NSString *filtered;
    // Check for period
    if ([textField.text rangeOfString:@"."].location == NSNotFound)
    {
        cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];
        filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
        return [string isEqualToString:filtered];
    }
    // Period is in use
    cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];
    filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    return [string isEqualToString:filtered];
}

Voila.

  • 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-14T23:21:04+00:00Added an answer on May 14, 2026 at 11:21 pm

    You will want to implement the UITextFieldDelegate Delegate on all of your textfields in a view cOntroller managing your view like so, making sure to validate your textfields after loading your view:

    -(void) viewDidLoad {
      textField1.delegate = self;  //Note if these were created in a xib, you can do this in IB
      textField2.delegate = self;
      [self validateTextFields];
    }
    

    And Implement the textField:shouldChangeCharatersInRage: method to due the validation everytime the textfileds change:

     - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
      [self validateTextFields];
      return YES;
    }
    

    Finally, do the actual validation and enable or disable your button as needed:

    -(void) validateTextFields {
      if ((textField1.text.length > 0) && textField2.text.length > 0)) {
        myUIButton.enabled = YES;
      }
      else {
        myUIButton.enabled = NO;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several old 3.5in floppy disks that I would like to backup. My
I have several HierarchicalDataTemplates in my TreeView. In one of them I would like
I have several active record models in a rails app and I would like
I have a sign-up form in my application with several UITextFields. In order to
I have a table with several text fields in it. Tapping on any of
I have several ASP:TextBox controls on a form (about 20). When the form loads,
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on
I have several tables whose only unique data is a uniqueidentifier (a Guid) column.
We have several jobs that run concurrently that have to use the same config
We have several wizard style form applications on our website where we capture information

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.