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

  • Home
  • SEARCH
  • 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 95151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:36:48+00:00 2026-05-10T23:36:48+00:00

I’m having quite a bit of pain inserting and deleting UITableViewCells from the same

  • 0

I’m having quite a bit of pain inserting and deleting UITableViewCells from the same UITableView!

I don’t normally post code, but I thought this was the best way of showing where I’m having the problem:


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {     return 5; }   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {      if (iSelectedSection == section) return 5;     return 1; }   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {      //NSLog(@'drawing row:%d section:%d', [indexPath row], [indexPath section]);      static NSString *CellIdentifier = @'Cell';      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];     if (cell == nil) {         cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];     }      if (iSelectedSection == [indexPath section]) {         cell.textColor = [UIColor redColor];     } else {         cell.textColor = [UIColor blackColor];     }          cell.text = [NSString stringWithFormat:@'Section: %d Row: %d', [indexPath section], [indexPath row]];      // Set up the cell     return cell; }   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     // Navigation logic -- create and push a new view controller      if ([indexPath row] == 0) {          NSMutableArray *rowsToRemove = [NSMutableArray array];         NSMutableArray *rowsToAdd = [NSMutableArray array];          for(int i=0; i<5; i++) {              //NSLog(@'Adding row:%d section:%d ', i, [indexPath section]);             //NSLog(@'Removing row:%d section:%d ', i, iSelectedSection);              [rowsToAdd addObject:[NSIndexPath indexPathForRow:i inSection:[indexPath section]]];             [rowsToRemove addObject:[NSIndexPath indexPathForRow:i inSection:iSelectedSection]];          }          iSelectedSection = [indexPath section];          [tableView beginUpdates];         [tableView deleteRowsAtIndexPaths:rowsToRemove withRowAnimation:YES];         [tableView insertRowsAtIndexPaths:rowsToAdd withRowAnimation:YES];         [tableView endUpdates];      } } 

This code creates 5 sections, the 1st (indexed from 0) with 5 rows. When you select a section – it removes the rows from the section you had previously selected and adds rows to the section you just selected.

Pictorally, when I load up the app, I have something like this:

http://www.freeimagehosting.net/uploads/1b9f2d57e7.png http://www.freeimagehosting.net/uploads/1b9f2d57e7.png

Image here: http://www.freeimagehosting.net/uploads/1b9f2d57e7.png

After selecting a table row 0 of section 2, I then delete the rows of section 1 (which is selected by default) and add the rows of section 2. But I get this:

http://www.freeimagehosting.net/uploads/6d5d904e84.png http://www.freeimagehosting.net/uploads/6d5d904e84.png

Image here: http://www.freeimagehosting.net/uploads/6d5d904e84.png

…which isn’t what I expect to happen! It seems like the first row of section 2 somehow remains – even though it definitly gets deleted.

If I just do a [tableView reloadData], everything appears as normal… but I obviously forefit the nice animations.

I’d really appreciate it if someone could shine some light here! It’s driving me a little crazy!

Thanks again, Nick.

  • 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. 2026-05-10T23:36:49+00:00Added an answer on May 10, 2026 at 11:36 pm

    FYI: This bug seems to have been fixed completely with the 2.2 iPhone update. Thanks Apple! Nick.

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

Sidebar

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer All DDL statements in Oracle PL/SQL should use Execute Immediate… May 11, 2026 at 8:54 am
  • added an answer This line is incorrect: ret_val = func(args) You're forgetting to… May 11, 2026 at 8:54 am
  • added an answer p.getElementsByTagName('Category')[0].firstChild minidom does not flatten away <![CDATA[ sections to plain… May 11, 2026 at 8:54 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.