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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:42:49+00:00 2026-06-05T18:42:49+00:00

I have a method, -(void)validateFormInput:(UITextField *)textField that gets called when the form’s submit button

  • 0

I have a method, -(void)validateFormInput:(UITextField *)textField that gets called when the form’s “submit” button is pressed. The method does the following:

1) Validates text in a given textField
2) If invalid, pops up an alert box, draws a red border around the UITextField and returns focus to that UITextField.

Problem is I am not getting focus back to the invalid UITextField.

Here is the validation method – Why is this not putting focus back on the invalid UITextField?

Thanks!

//Called when form "submit" button is pressed
-(void)validateFormInput:(UITextField *)textField{
    //If Validation fails... 
    if([textField.text length] <1){ 
        //simple test case        
        textField.layer.borderWidth = 2.0f;
        textField.layer.borderColor = [[UIColor redColor] CGColor];
        textField.layer.cornerRadius = 5;
        textField.clipsToBounds = YES;

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
            message:@"Please add a title"
            delegate:nil
            cancelButtonTitle:@"OK"
            otherButtonTitles: nil];
        [alert show];
        alert = nil;
        [textField becomeFirstResponder];               
    }
}
  • 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-05T18:42:51+00:00Added an answer on June 5, 2026 at 6:42 pm

    You need to add delegate to self and implement delegate method alertView:didDismissWithButtonIndex:. Dont forget to conform to UIAlertViewDelegate protocol.

    When this method gets called make your textField first responder.

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

Sidebar

Related Questions

Assume I have method void SomeMethod(Action callback) This method does some work in background
I have a method void DoWork(object input) that takes roughly 5 seconds to complete.
Imagine, that u have a Method: public void SometimesIFail(string text) { bool everythingOk =
I have a method -(void)foo that I want to call once in viewDidAppear ,
I have the following method: -(void)SomeMethod:(id)classOrProtocol; It will be called like this: [self someMethod:@protocol(SomeProtocol)];
Given that you have a method -(void)aSelector:(id)anyArgument; And have set up a UIButton programmatically
I have a method -(void)myMethod:(MyObject*)obj And I am detaching a new thread [NSThread detachNewThreadSelector:@selector(myMethod)
If I have this method: -(void) methodName { action1; action2; [self methodName]; } I
Imagine I have a method: void Method(bool parameter){ if(parameter){ // first case } else
I currently have this method: -(void)seperateGuides { DLog(GetGuideListCount: %i, [[appDelegate getGuideList] count]); columnOneArray =

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.