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

The Archive Base Latest Questions

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

In my app, i have two textfields(username and Password) and UIbutton in SignIn page.

  • 0

In my app, i have two textfields(username and Password) and UIbutton in SignIn page.

I want to enable button if textfield(password) having text.

I have created the UITextfield and UIbutton with below property in viewDidLoad().

 self.txtFieldPassword.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.btnLogin setEnabled:NO];

I have tried the below code and there is no luck.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField == self.txtFieldPassword) {

    // checking for any whitespaces
    if(([string rangeOfString:@" "].location != NSNotFound))
    {
        return NO;
    }  

    if( [[self.txtFieldPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] )
        self.btnLogin.enabled = YES;
    else
        self.btnLogin.enabled = NO;
}

return YES;
}

but, if i removed the below line in UitextField means, it have worked.

self.txtFieldPassword.clearButtonMode = UITextFieldViewModeWhileEditing;

i want to enable button with the above property. How to achieve it?

Thanks!!!

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

    You can just check for string.length == 0 and range.length > 0; this denotes a deletion. However what you really want is to just do the pending modification and then check that you still have a non-empty string.

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *testString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    testString = [testString stringByTrimmingCharactersInSet:
                  [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if( testString.length)
        myButton.enabled = YES;
    else
        myButton.enabled = NO;
    }
    - (BOOL)textFieldShouldClear:(UITextField *)textField{
     _done_button.enabled = NO;
      return YES;
    }
    

    you can achieve this with self.txtFieldPassword.clearButtonMode = UITextFieldViewModeWhileEditing; property. it is working fine for me, have a great day

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

Sidebar

Related Questions

In my iPad app I have two textfields. One displays the normal, default textfield
I have an App that I want to have two version in the App
I have two applications in CakePHP, App A an App B. I want that
I am working on an iPhone/iOS app. It have a login page with two
Please need help : I have two textfield in a view , save button
In my Iphone app I have to add textfield at two rows of tableview
I have two app icons built-in (free and premium), is it possible to replace
Is it possible to have two app.config files where one app.config serves as a
I am developing a web app that will have two parts running on two
I have two UIDatePicker controls in my app, one configured with UIDatePickerModeDate and one

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.