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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:31:11+00:00 2026-06-14T10:31:11+00:00

short version : How can I make a UITextField box remove all content on

  • 0

short version: How can I make a UITextField box remove all content on the users first keypress? I don’t want the info removed until the user starts typing something. ie, clearing it on begin edit is not good enough.

long version: I have three UITextField that loop around (using the return key and catching the press in the “shouldReturn” method. There is text already in the UITextField, and if the user doesn’t type anything and just goes to the next UITextField, the value should stay (default behaviour).

But I want it that if the user starts typing, it automatically clears the text first. Something like having the whole field highlighted, and then typing anything deletes the fiels and then adds the user keypress.

“Clear when editing begins” is no good, because the text is immediately cleared on the cursor appearing in the field. That’s not desired. I thought I could use the placeholder here, but that doesn’t work as a default, and I can’t find a default value property. The Highlighted and Selected properties don’t do anything in this regard either.

  • 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-06-14T10:31:14+00:00Added an answer on June 14, 2026 at 10:31 am

    Declare a BOOL variable in your .h file like.

    BOOL clearField;
    

    And implement the delegate methods like:

    -(void)textFieldDidBeginEditing:(UITextField *)textField
    {
       clearField = YES;
    }
    
    -(void)textFieldDidEndEditing:(UITextField *)textField
    {
      clearField = NO;
    }
    
    -(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
      clearField = NO;
    }
    
    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
      if(clearField)
      {
         textField.text = @""
         clearField = NO;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: Can I grant access to external databases to a role? Long version:
Short version: How can I map two columns from table A and B if
SHORT VERSION OF QUESTION: So basically my question is: How can I set the
The short version of the question - why can't I do this? I'm restricted
So the short version of this is: Can I traverse only the elements within
Short version: I have a similar setup to StackOverflow. Users get Achievements. I have
Short version (if you can answer the short version it does the job for
Short version of what I want to accomplish : I have a foot pedal
Short Version For those who don't have the time to read my reasoning for
Short story: I want to make slight changes to the behavior of a MainClass,

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.