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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:23:10+00:00 2026-05-22T20:23:10+00:00

I have a UITableView with about 20 cells, in each cell there are three

  • 0

I have a UITableView with about 20 cells, in each cell there are three UITextFields. I did NOT subclass UITableViewCell, but when setting up each cell I set the textfields tag value to a constant plus the row number. So for each row the tag of the textfield is incremented by one.

When I run the app and enter a value in for example row one, it may reappear on row 12. The behavior is not the same each time i run the app.

I should add that I have an array storing the contents entered in each textfield. When a textfield is edited, I save the new value to the array and when the cell is again requested by the tableview i set the textfields value to that stored in the array.

Does this have something to do with reusing UITableViewCells?
When reusing a cell, can textfields in different rows get the same tag numbers? Say for example that the first cell (textfield tag=1001) is reused on row 12, then we have two textfields with the same tag number. If I then enter a value on row 1 and later load row 12, the value from cell one will be loaded from the array and put in row 12 also.

If this is happening, how do I fix it?
Each cell does not have a reference to the textfield, so I don’t think I can edit a textfield’s tag value by just having access to the cell which it is in.

EDIT:

Here is the code for UITableView:cellForRowAtIndexPath:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            //Modify cell, adding textfield with row-unique index value
            cell = [self modifyCellForHoleInfo:cell atIndexPath:indexPath];

    }
    cell.accessoryType = UITableViewCellAccessoryNone; 

    // Load value for textfield stored in dataArray
    ((UITextField *)[cell viewWithTag:1000+indexPath.row]).text = [dataArray objectAtIndex:indexPath.row];

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-22T20:23:11+00:00Added an answer on May 22, 2026 at 8:23 pm

    The issue is that when the cell is reused (i.e. dequeueReusableCellWithIdentifier returns non-nil), the cell is returned with the existing UITextView. To maintain the uniqueness of the tags, it’ll be better to remove any previous UITextField:

    - (void)removeExistingTextSubviews:(UITableViewCell *)cell
    {
        NSMutableArray *toRemove = [NSMutableArray array];
        // I don't know if you have non-TextField subviews
        for (id view in [cell subviews]) {
            if ([view isKindOfClass:[UITextField class]] && view.tag >= 1000) {
               [toRemove insert:view];
            }
        }
    
        for (id view in toRemove) {
            [toRemove removeFromSuperView];
        }
    }
    
    ...
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    } else {
        [self removeExistingTextSubviews:cell];
    }
    //Modify cell, adding textfield with row-unique index value
    cell = [self modifyCellForHoleInfo:cell atIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryNone; 
    
    // Load value for textfield stored in dataArray
    ((UITextField *)[cell viewWithTag:1000+indexPath.row]).text = [dataArray objectAtIndex:indexPath.row];
    

    Please note that I haven’t compiled the code, but it should serve as a starting point.

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

Sidebar

Related Questions

I have gone through Apple docs about UITableView class and delegate reference but couldn't
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *TelephoneCellId = @TelephoneCellId; UITableViewCell *cell
(This is about programatically swapping the style of existing tableview and not about setting
I've put some UITextViews in a UITableView(Controller) with custom cells, and I'm running into
I have run into a bit of a problem. Usually when dealing with UITableView
I have a app that will populate a UITableView after the user takes a
been confused about this for over two hours, so maybe someone can point me
I have a problem with memory leak warning when releasing an object after returning
I have spent hours reading a couple dozen different blogs and others q's here
I am trying to measure the scrolling performance for my UITableView, between using subview

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.