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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:09:12+00:00 2026-05-27T20:09:12+00:00

I have created a UITableView with two cells, username and password using the code

  • 0

I have created a UITableView with two cells, username and password using the code below.

I have included a screenshot of the output the first time the view loads (the expected output) and the second time the view is shown (the incorrect output)

Expected result Incorrect result on second load

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

    UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];
    if( cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Login Ident"];   

    if (indexPath.row == 0) {
        loginId = [[UITextField alloc] initWithFrame:CGRectMake(5, 0, 280, 21)];
        loginId .placeholder = @"Email address";
        loginId .autocorrectionType = UITextAutocorrectionTypeNo;
        [loginId setClearButtonMode:UITextFieldViewModeWhileEditing];
        cell.accessoryView = loginId;
    }
    if (indexPath.row == 1) {
        password = [[UITextField alloc] initWithFrame:CGRectMake(5, 0, 280, 21)];
        password.placeholder = @"Password";
        password.secureTextEntry = YES;
        password.autocorrectionType = UITextAutocorrectionTypeNo;
        [password setClearButtonMode:UITextFieldViewModeWhileEditing];
        cell.accessoryView = password;
    }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    loginId.delegate = self;
    password.delegate = self;

    [loginId setText:[keychain objectForKey:(__bridge id)kSecAttrAccount]];
    [password setText:[keychain objectForKey:(__bridge id)kSecValueData]];

    [loginId addTarget:self 
                    action:@selector(textFieldReturn:)
          forControlEvents:UIControlEventEditingDidEndOnExit];
    [password addTarget:self 
                action:@selector(textFieldReturn:)
      forControlEvents:UIControlEventEditingDidEndOnExit];

    [cell.contentView addSubview:loginId];
        [cell.contentView addSubview:password];

    }


    return cell;  
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [_tableView reloadData];
}

My UITextField declarations

UITextField *loginId; 
UITextField *password;

If anybody is able to help me out with this, I’d really appreciate it.

With changes

enter image description here

  • 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-27T20:09:12+00:00Added an answer on May 27, 2026 at 8:09 pm

    You should put the code where you create the text fields inside the if (cell == nil) {} since otherwise you could be adding a second textfield to a cell that’s already been created previously. If that doesn’t fix the issue post back.

    Also, remove:

    [_tableView addSubview:loginId];
    [_tableView addSubview:password];
    

    You shouldn’t add views that are meant for the cells to the tableview. And instead of making it the accessoryView of the cell, add them to the contentView

    [cell.contentView addSubview:loginId];
    

    See chat below for full resolution of the issue.

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

Sidebar

Related Questions

I have created a UITableView with two cells, username and password using the code
I have created a UItableView using the default Xcode template and configure it to
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a C# class file by using a XSD-file as an input.
I have a TabBar App. I have created a UITableView class called Schedule that
I have a UIViewController with two UI Components: UITableView and UIDatePicker. My goal is,
i have created a TabBar Application. I Added to a view an UITableView and
I have a UITableView that I never want to fall below 1 cell: It's
I want to add multiple columns in UITableView. I have created one CustomeTableCell with
I have a UITableView with custom cell. I have created seperate class with xib

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.