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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:02:43+00:00 2026-06-17T03:02:43+00:00

I have a simple UITableView with 1 section, within which an arbitrary amount of

  • 0

I have a simple UITableView with 1 section, within which an arbitrary amount of rows with custom UITableViewCells (of type KMInputCell) with UITextFields exist. When a user starts typing in the last (blank) text field, a new blank row is inserted (so the user can make a list-like structure). Since I will only “save” the data when the view is closed, the data source is just an NSUInteger keeping track of the number of rows.

My code works fine until after a user has deleted a row from the table. Then, when the user starts typing at the end of the list and a new (blank) row should be inserted, the inserted UITableView cell contains old data from the deleted cell. Worse, when multiple rows are deleted and then the user starts typing (and one blank row should be inserted), multiple deleted rows become suddenly present.

Here is the fieldChanged: method that is called when one of the UITextFields in the cells is edited (where self.last_cell returns the last cell in the section):

- (IBAction)fieldChanged:(id)sender {
    // get the text field of the last row
    // if it has a value that is not blank, insert another row
    KMInputCell* last_cell = self.last_cell;
    if(![last_cell.textField.text isEqualToString:@""]){
        [self.tableView beginUpdates];
        NSIndexPath* new_cell_path = [NSIndexPath indexPathForItem:[self.tableView numberOfRowsInSection:0] inSection:0];
        [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:new_cell_path] withRowAnimation:UITableViewRowAnimationAutomatic];
        number_emails++;
        [self.tableView endUpdates];
    }
}

Here is the commitEditingStyle: method that is used to delete cells:

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        number_emails--;
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
     }   
}

Addition

Here is cellForRowAtIndexPath::

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"add_email_prototype";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];=

    // Configure the cell...

    return cell;
}
  • 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-17T03:02:44+00:00Added an answer on June 17, 2026 at 3:02 am

    I’m not exactly clear on the particulars of your data model… just keeping track of an integer isn’t really a great approach – but perhaps I just don’t understand what you’ve got going on. Do you have a model array or model objects representing these rows, or are you just tracking the text in their fields?

    You’re inserting new rows, but the issue might pertain to the fact the UITableViewCells are reused when being presented. If that is indeed the problem here, you may need to update a method you haven’t provided here:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
        // Configure the cell...
    
        return cell;
    }
    

    This should be the method you are using to populate the text fields. It is necessary as well, to explicitly clear the contents of any dynamic fields such that, when table cells are re-used, you don’t get unexpected contents in them.

    UPDATED

    Text fields themselves aren’t suitable for retaining data. The architecture, as you can see from the issue here, precludes it because the cells are re-used as they scroll on and off the screen (or are removed/added). One course of action would be to just create an array and store the contents of these textfields as strings within it.

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

Sidebar

Related Questions

I have a simple UITableView with two sections. Each section has a header which
I have a very simple UITableView that has 3 sections, and 3 rows per
I've simple UITableView with one section and few rows. When user clicks cell accessory
I have a setup with sections in a UITableView which all have a custom
I have set up a UITableView which has 3 sections in, with 3 rows
I have a simple UITableView (with 1 section), my dataSource is a NSMutableArray of
I have simple class with width and height member fields which define number of
I have a simple UITableView, and I want to add a checkmark whenever I
I have an UITableView with sections and many rows. I don't need a detailed
I have a simple table view which I have built using an example from

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.