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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:58:53+00:00 2026-05-26T03:58:53+00:00

Possible Duplicate: Assign a method for didEndOnExit event of UITextField How can I add

  • 0

Possible Duplicate:
Assign a method for didEndOnExit event of UITextField

How can I add didEndOnExit to a UITextField in pure code rather than IB?

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-26T03:58:54+00:00Added an answer on May 26, 2026 at 3:58 am

    Assuming your talking about textFieldDidEndEditing: or textFieldShouldReturn:. You would implement the method in your view controller, and set the text fields delegate to self like so:

    - (void)viewDidLoad {
        [super viewDidLoad];
        // ....
        myTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 50, 25)];
        myTextField.delegate = self;
        [self.view addSubview:myTextField];
    }
    
    - (void)textFieldDidEndEditing:(UITextField *)textField {
        if (textField == myTextField) {
            // Do stuff...
        }
    }
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        if (textField == myTextField) {
            return YES;
        }
        return NO;
    }
    
    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        if ((myTextField.text.length + string.length) < 5) {
            return YES;
        }
        return NO;
    }
    

    Then, in your header file in the @interface you can specify that you are a UITextFieldDelegate like this:

    @interface MyViewController : UIViewController <UITextFieldDelegate> {
        // ....
        UITextField *myTextField;
        // ....
    }
    
    // Optionally, to make myTextField a property:
    @property (nonatomic, retain) UITextField *myTextField;
    
    @end
    

    UITextField Reference
    UITextFieldDelegate Reference


    Edit (as per your comment, this should work):

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        if ((myTextField.text.length + string.length) < 5) {
            return YES;
        }
        return NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Create shortcut to console.log() In javascript we can easy assign functions to
Possible Duplicate: How To Set Text In An EditText how can we assign value
Possible Duplicate: C# Why can't an anonymous method be assigned to var? I have
Possible Duplicate: How do I assign by “reference” to a class field in c#?
Possible Duplicate: Double Negation in C++ code Let's say: bool var = !!true; It
Possible Duplicate: declare property as object? in java you can create an object directly
Possible Duplicate: How to assign Profile values? I'm using ASP.NET MVC and the Membership
Possible Duplicate: Is it possible to call Ant or NSIS scripts from Java code?
Possible Duplicate: What does the >?= operator mean? I found this code segment ...
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)

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.