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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:57:36+00:00 2026-05-21T18:57:36+00:00

I have a tableview with four sections and all of the sections have two

  • 0

I have a tableview with four sections and all of the sections have two textfields and a label in different rows. I have added some text as placeholder of textfield. Initially the data appears fine but when I scroll the tableview the cell starts to have overlapped data.
My Code:

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.row==0) {
    UITextField *txtName = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, 300, 30)];
    txtName.placeholder = @"Full Name";
    [cell.contentView addSubview:txtName];
    [txtName release];
}
else if(indexPath.row==1) {
    UITextField *txtEmail = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, 300, 30)];
    txtEmail.placeholder = @"Email";
    [cell.contentView addSubview:txtEmail];
    [txtEmail release];
}
else if(indexPath.row==2){
    cell.textLabel.text = @"Select Date of Birth";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell...

return cell;

}

thanks in advance
Pankaj

  • 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-21T18:57:37+00:00Added an answer on May 21, 2026 at 6:57 pm

    You need to create your text fields only in the block of code that inits the cell. Remember that the table view recycles cells so as you scroll off the screen you get a reused and recycled cell that already has a textfield. You are then creating a new textfield and overlaying the new textfield on the existing one, hence you get overlapping.

    here is your code properly refactored

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
            //create the textField here, and we will reuse it and reset its data for each row.
            UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, 300, 30)];
            [cell.contentView addSubview:txtField];
            txtField.tag=110; //should declare a constant that uniquely defines your textField;
            [txtField release];
    
        }
    
        // Configure the cell...
    
        //ok, now we retrieve the textField and set its data according to the row.
        UITextField *txtField = (UITextField *)[cell.contentView viewWithTag:110];
    
        if(indexPath.row==0) {
            txtField.placeholder = @"Full Name";   
        }
        else if(indexPath.row==1) {
            txtField.placeholder = @"Email";    
        }
        else if(indexPath.row==2){
            txtField.placeholder = nil;  //? did you mean to set something here?
            cell.textLabel.text = @"Select Date of Birth";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    
    
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tableview with four sections first section has 7 rows in that
I have a tableview with a navigation bar at the top. I've added text
I have a table with four rows. Two of them should be displayed initially
Currently I have Long Pres Gesture Recognizers on four different TableViews (two in each
I have TableView which number of rows depends on the number of NSStrings in
I have a tableView with sections, which could be opened and closed. So, when
I have tableview with some names on each cell , how can i get
I have four sections in my UITableView, how do I add a header for
In my root view, I have a tableview with three rows. When I click
i have tableview with custom cell.the table is divided in many section and rows.i

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.