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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:50:02+00:00 2026-06-09T09:50:02+00:00

I have ageTextField property in my TableViewController . I add it to the first

  • 0

I have ageTextField property in my TableViewController. I add it to the first section cell’s subciew but I don’t know why it is shown in another section (#3) when I scroll down..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    switch (indexPath.section){
        case 0:
        {
            [cell addSubview:self.ageTextField];
        }
        break;
        case 1:
        {
            cell.textLabel.text = [screeningArray objectAtIndex:indexPath.row];
            if (indexPath.row == 0)     //no choice
                cell.accessoryType = self.doneScreening ? UITableViewCellAccessoryNone:UITableViewCellAccessoryCheckmark;
            else                        //yes choice
                cell.accessoryType = self.doneScreening ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
        }
        break;
        case 2:
        {
            cell.textLabel.text = @"1 : ";
            [cell addSubview:self.riskTextField];
        }
        break;
        case 3:
        {
            cell.textLabel.text = [findingsArray objectAtIndex:indexPath.row];
            cell.accessoryType = [[boolValuesArray objectAtIndex:indexPath.row] boolValue] ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
        }
        break;
        default:
        break;
    }
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    return cell;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSUInteger newLength = [textField.text length] + [string length] - range.length;
    if (textField == self.ageTextField)
        return (newLength > 2) ? NO : YES;
    else
        return (newLength > 7) ? NO : YES;
}

Here is screenshot at the beginning..

http://dl.dropbox.com/u/30838210/Screen%20Shot%202012-08-07%20at%209.26.47%20PM.png

After scrolling down, notice how the placeholder of ageTextField was duplicated in Section3, cell3..

http://dl.dropbox.com/u/30838210/Screen%20Shot%202012-08-07%20at%209.27.28%20PM.png

When scrolling up again, the text of cell3 in section3 appears in the first cell..

dl.dropbox.com/u/30838210/Screen%20Shot%202012-08-07%20at%209.27.52%20PM.png

That’s weird and I couldn’t figure out what happened! please help..

  • 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-09T09:50:03+00:00Added an answer on June 9, 2026 at 9:50 am

    The contents of a table view cell must be removed if they are reused (i.e, if cell != nil). Also, the subviews should be added to the table cell’s contentView not to the cell itself, so the subviews adjust appropriately when entering/exiting editing mode.

            [cell.contentView addSubview:self.ageTextField];
    
            [cell.contentView addSubview:self.riskTextField];
    

    The following code prepares the cell for reuse.

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    else
    {
        // Prepare cell for reuse
    
        // Remove subviews from cell's contentView
        for (UIView *view in cell.contentView.subviews)
        {
            // Remove only the appropriate views
            if ([view isKindOfClass:[UITextField class]])
            {
                [view removeFromSuperview];
            }
        }
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.textLabel.text = nil;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a recurring situation, petty I know, but I'd like to consolidate the following:
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have a big problem since a few days that I can't solve. First
Have converted devise new session from erb to Haml but doens't work, this is
Have searched the database but need to specifically sum(of hours flown or days off)in
Have searched for the answer but no joy, so here goes... I'm working on
Have had to write my first proper multithreaded coded recently, and realised just how
Have a question about calling one prototype function in another prototype function. for instance
Have I lost it, but if feels like I remember doing something along the
have written this little class, which generates a UUID every time an object of

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.