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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:19:46+00:00 2026-05-23T00:19:46+00:00

I have 4 UITextFields that I am using to keep 2 UIButtons disabled until

  • 0

I have 4 UITextFields that I am using to keep 2 UIButtons disabled until all 4 fields have data entered into them. I have the following code so far

- (void)textFieldDidBeginEditing:(UITextField *)textField {


if (([brand.text length] >0) && ([qty.text length] >0) && ([size.text length] >0) && ([price.text length] >0)) {
    [calcOneButton setEnabled:YES];
    [calcTwoButton setEnabled:YES];

}else {

}


}

I have a number of problems with this :-

  1. When data is removed from the fields the UIButtons are still enabled
  2. The Buttons arent enabling correctly, after I have entered data into all 4 fields I need to re-tap on a field to enable the button.
  3. I am logging the length of each field but as a character is entered it starts at a count of 0 not 1.

Can anyone help with these points?

The code for logging the length of a field is as follows :-

#define MAXLENGTH 5
#define MAXQTY 3
#define MAXSIZE 4
#define MAXBRAND 10

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
if (textField == brand) {
    int lengtha = [brand.text length] ;
    NSLog(@"lenghta = %d",lengtha);
    if (lengtha >= MAXBRAND && ![string isEqualToString:@""]) {
        brand.text = [brand.text substringToIndex:MAXBRAND];
        return NO;
    }

it follows the same format for all 4 fields, but as I enter a character the NSlog results as a 0 then 1 for the second character and so on.

  • 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-23T00:19:47+00:00Added an answer on May 23, 2026 at 12:19 am

    Just use another delegate-method.

    Either use: textFieldDidEndEditing: like Krypton told you in a comment

    or use textField:shouldChangeCharactersInRange:replacementString: for enable/disable directly when typing.

    textField:(UITextField*)aTextField shouldChangeCharactersInRange:(NSRange) aRange replacementString:(NSString*)aRepString
    {
        NSString *newStr = [aTextField.text stringByReplacingCharactersInRange:aRange withString:aRepString];
        if([newStr length]>0 && /*otherStringLength > 0*/)
              //enable
        else
              //disable
        return YES;
     }
    

    But I think the most common way is to use the didEndEditing-method

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

Sidebar

Related Questions

I have two fields that call UIPickerView (Country and Province). I'm using inputView to
I have a UITextField that I put into a UITableViewCell that I put into
Scenario: I have 4 UITextFields that only accept 1 character. Easy. Problem: After I
In my iPhone project I'm using a UITableview with UITableViewCells containing UITextfields. I have
I have a TableViewController that is using a grouped Style and has two(2) sections.
I have run into an issue that I have yet to be able to
I have an ipad app, that as user does some actions, uitextfields and buttons,
I have a UIScrollView to which I append multiple custom UIView's that contain UITextFields...
I have several UITextFields. I want to disable the double tap that brings the
I have UITextFields on a table to enter values. Some of these fields accept

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.