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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:14:12+00:00 2026-05-28T03:14:12+00:00

I have a UITextField and I create it like so: firstnameField1 = [[UITextField alloc]

  • 0

I have a UITextField and I create it like so:

firstnameField1 = [[UITextField alloc] initWithFrame:CGRectMake(85+320*4, 80, 150, 30)];
    [firstnameField1 setBorderStyle:UITextBorderStyleRoundedRect];
    [firstnameField1 setPlaceholder:@"Firstname"];
    [firstnameField1 setDelegate:self];
    [firstnameField1 setReturnKeyType:UIReturnKeyNext];
    [scrollViewController addSubview:firstnameField1];

When the user taps the return key I want to check if the text field has anything typed into it, if its empty, the user hasn’t typed anything, I want to return and show a label telling the user that field is required to be filled before they can continue, just like you see all over the place.

I do the following to check:

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //Check if the user has typed anything
    if (textField.text == @"") {
        //If not, show 'required' labels
        [firstNameRequiredLbl1 setAlpha:1];
        [surnameRequiredLbl1 setAlpha:1];
        [firstNameRequiredLbl2 setAlpha:1];
        [surnameRequiredLbl2 setAlpha:1];
        return YES;
    }

    //Do all my other stuff, cut out for ease of reading, 100% doesn't affect this anyway

    return YES;
}

I have set a breakpoint on that last method and it jumps right past that if statement whether I type into that textfield or not.

Any ideas? 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-28T03:14:13+00:00Added an answer on May 28, 2026 at 3:14 am

    You’ll want to change textField.text == @""

    to: textField.text.length == 0 or textField.text isEqualToString:@""

    What the == operator is actually doing in this case is checking if the strings are stored in the same area of memory rather than whether or not they contain the same characters.

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

Sidebar

Related Questions

I have an UITextField and I would like that for every tap on a
I have a UITextField that I would like to enable auto completion on by:
I would like to have a UITextField or UITextView in where as I do
How would I create an Offscreen UITextField? Would it be: theTextField = [[UITextField alloc]
I have create UITextField with alert view. After typing on UITextField I want to
I have discovered that I can create UILabel much faster than UITextField and I
I created a UITextField in code, now I have now idea how to define
I have a UITextField that I put into a UITableViewCell that I put into
I have a UITextField but when it overflows I want it to scroll not
I have a UITextField in my app that accepts decimal amounts for prices (i.e.,

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.