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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:22:13+00:00 2026-06-17T17:22:13+00:00

iPhone App : i have a screen with 3 textfields to enter name, email

  • 0

iPhone App :

  • i have a screen with 3 textfields to enter name, email and location.
  • i have used grouped table view with 2 sections.
  • in tat first section has three cells.. each cell has a label n a textfield.. eg: label called name and a text box to enter name.. like wise i have it for email and location too..

HAVE DECLARED nameTextField, emailTextField, locationTextField in the interface as variables and not properties. so pls tell me how to dismiss the keyboard here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    CommonTableViewCell* cell = [[CommonTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@""];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor blackColor];
    cell.textLabel.highlightedTextColor = [UIColor whiteColor];
    cell.textLabel.font = [UIFont fontWithName:@"Arial" size:14];//
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
    //cell.image = [UIImage imageNamed:@"resources_on.png"];
    cell.textLabel.frame = CGRectMake(TABLE_ROW_HEIGHT + 10, 5, self.view.frame.size.width , 25);

    if (indexPath.section == 0) {
        if (indexPath.row  == 0) {
            cell.textLabel.text = @"Username";

            nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(140, 18, 300, 20)];
            [nameTextField setBackgroundColor:[UIColor clearColor]];
            [nameTextField setFont:[UIFont fontWithName:@"Arial" size:14]];
            nameTextField.placeholder = @"Enter anonymous name";
            [nameTextField setKeyboardType: UIKeyboardTypeNamePhonePad];
            [cell addSubview:nameTextField];
            [nameTextField release];

        }else if (indexPath.row == 1) {

            cell.textLabel.text = @"Email"; 
            emailTextField = [[UITextField alloc] initWithFrame:CGRectMake(140, 18, 300, 20)];
            [emailTextField setBackgroundColor:[UIColor clearColor]];
            [emailTextField setFont:[UIFont fontWithName:@"Arial" size:14]];
            emailTextField.placeholder = @"example@me.com";
            [emailTextField setKeyboardType:UIKeyboardTypeEmailAddress];
            [cell addSubview:emailTextField];
            [emailTextField release];

        }else if (indexPath.row == 2) {

            cell.textLabel.text = @"Location";
            locationTextField = [[UITextField alloc] initWithFrame:CGRectMake(140, 18, 300, 20)];
            [locationTextField setBackgroundColor:[UIColor clearColor]];
            [locationTextField setFont:[UIFont fontWithName:@"Arial" size:14]];
            locationTextField.placeholder = @"Fetch";
            [cell addSubview:locationTextField];
            [locationTextField release];

        }else if (indexPath.row == 3) {

            cell.textLabel.text = @"Terms of Use";

            cell.thumbnailView.image = [UIImage imageNamed:@"compensation_on.png"];

        }else if (indexPath.row == 4) {

            cell.textLabel.text = @"Privacy Policy";

            cell.thumbnailView.image = [UIImage imageNamed:@"compensation_on.png"];

        }else {

        }
    } else if (indexPath.section == 1) {
        if (indexPath.row == 0) {

            cell.textLabel.text = @"Terms of Use";

            cell.thumbnailView.image = [UIImage imageNamed:@"compensation_on.png"];

        }else if (indexPath.row == 1) {

            cell.textLabel.text = @"Privacy Policy";

            cell.thumbnailView.image = [UIImage imageNamed:@"compensation_on.png"];

        }else {

        }

    }


    return cell;
}

and this isnt working for me..

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
    return YES; 
}
  • 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-17T17:22:14+00:00Added an answer on June 17, 2026 at 5:22 pm

    You should assign a delegate to your UITextFields.

    Your datasource (or any other object, but this one seems ok for the job) should conform to <UITextFieldDelegate> protocol.

     ...
     nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(140, 18, 300, 20)];
     [nameTextField setBackgroundColor:[UIColor clearColor]];
     [nameTextField setFont:[UIFont fontWithName:@"Arial" size:14]];
     nameTextField.placeholder = @"Enter anonymous name";
     [nameTextField setKeyboardType: UIKeyboardTypeNamePhonePad];
    
     [nameTextField setDelegate:self]; //add this line
    
     [cell addSubview:nameTextField];
     //[nameTextField resignFirstResponder]; this doesn't really make sense - creating the text
     //field should not (and does not) bring up the keyboard
     [nameTextField release];
     ....
    

    Do the same for other UITextFields.

    Then check if your delegate method gets called (using NSLog for example, or breakpoints):

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        NSLog (@"should return?"); 
        [textField resignFirstResponder]; 
        return YES; 
    }
    

    EDIT:

    You only have to set the delegate once for each UITextField – usually when it’s created.

    To tell the compiler that a certain class confroms to <UITextFieldDelegate> protocol just add after the class @interface declaration in header file.

    For example, if the class that you use as a dataSource for the table is named MyDataSource:

    @interface MyDataSource: NSObject <UITableViewDelegate,UITextFieldDelegate>
    

    Of course you have to implement all the required methods to correctly conform to a certain protocol.
    Please check the documentation: UITextFieldDelegate Protocol Reference

    EDIT: as for checking the validitiy of email: you can check the validity (this is actually another question) you can do this in - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

    Since your delegate object is delegate to more then one UITextField you’ll have to check first if text field being edited is the one holding the email. And since your text fields are in table cells it would be hard (and unceccessary) to hold reference to all of them. You can separate email text fields from the others by using tag – let’s make it 44. Modify your code slightly:

    emailTextField = [[UITextField alloc] initWithFrame:CGRectMake(140, 18, 300, 20)];
    emailTextField.tag = 44; //add this line
    

    Then add the delegate method:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        if (textField.tag == 44)
        {
            //email checking code here
        }
        else
        {
            return YES;
        }
    }
    

    As for how to check email, take a look at this answer: https://stackoverflow.com/a/7707946/653513

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

Sidebar

Related Questions

I have an iPhone app which has a Table View-based data input screen with
In my iPhone app I have a table view where I add a tick
I am making an IPhone app and I have a table view that is
I have an iPhone app that has several different view controllers. A login screen
I have an iphone app i want that befor moving to next screen it
I'd like to have an image in my iphone app pop-in on screen rather
I have an iPhone app containing a UITableView in grouped style. In the ViewController
I have a Default.png for my splash screen image at my iphone app. After
I have this scroll view problem.I have 2 screens in my app, Screen A
In my iPhone app, I have an image on the screen (UIImageView). I would

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.