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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:48:31+00:00 2026-06-01T13:48:31+00:00

I have a multi-section tableview. In edit mode I allow rows to be moved

  • 0

I have a multi-section tableview. In edit mode I allow rows to be moved from one section to another. Once the final row is removed from one section I delete that section. So I am using deleteSection inside moveRowAtIndexPath.

When the final item is moved from the section, the section header disappears as planned. But there is a very strange animation bug, where the moved row seems to ‘merge’ with the row it is dropped above, and an empty row is displayed at the bottom of the ‘to’ section (probably because the numberOfRows for that section is correct, but 2 rows are in the same position). Even stranger, when I click the reorder control for this row (not moving the item, simply touching and releasing), the two items ‘unmerge’.

I have posted a video demonstrating this.

I have tried wrapping my data changes and view changes in begin/end updates, but to no avail.

I have uploaded a test project here, and I will also post the code below. A couple of points:

  • I have tried to replicate my data source’s format in the demo project, in case this is where the problem originates. The key thing is that my source is a composite array of two other arrays (though I can’t see why this would be an issue).
  • To see the behavior in question, move the two rows in the bottom section, up into the top section. Don’t drop them in the last row on the top section though, since this seems to work ok.
  • Moving rows the other way, from the top section to the bottom section, is buggy in this demo project.

Code (all of this is in the demo project):

I set up my arrays in loadView:

- (void)loadView{
array1 = [NSMutableArray array];
[array1 addObject:@"test 0"];
[array1 addObject:@"test 1"];
[array1 addObject:@"test 2"];

    array2 = [NSMutableArray array];
    [array2 addObject:@"test a"];
    [array2 addObject:@"test b"];

    [super loadView];
}

I also have a method that returns a combination of these arrays – this is used as the data source:

- (NSMutableArray *)sourceArray{
NSMutableArray *result = [NSMutableArray array];
if (array1.count > 0) {
    [result addObject:array1];
}
if (array2.count >0) {
    [result addObject:array2];
    }
    return result;
}

Which allows for very simple number of rows/sections:

   - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return self.sourceArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [[self.sourceArray objectAtIndex:section] count];
}

Standard Cell/Header formatting:

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.textLabel.text = [[self.sourceArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [NSString stringWithFormat:@"Section %i", section];
}

This is where I do the magic

    // Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
    NSMutableArray *fromArray = [self.sourceArray objectAtIndex:fromIndexPath.section]; 
    NSMutableArray *toArray = [self.sourceArray objectAtIndex:toIndexPath.section];

    NSString *movedObject = [[self.sourceArray objectAtIndex:fromIndexPath.section] objectAtIndex:fromIndexPath.row];

    [fromArray removeObject:movedObject];
    [toArray insertObject:movedObject atIndex:toIndexPath.row];

        if ([self.tableView numberOfRowsInSection: fromIndexPath.section] == 0) {
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:fromIndexPath.section] withRowAnimation:UITableViewRowAnimationFade];
        }
    }
  • 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-01T13:48:32+00:00Added an answer on June 1, 2026 at 1:48 pm

    I notice that the row that comes from the to-be-deleted section is the one that disappears until you retouch the order control.

    I suspect that when this datasource method is called by the tableview, its state is still in the middle of performing the move, so calling ‘deleteSections’ will make the table try and delete the row you’re moving. It’s not so much of a merge as the fact that it’s fading away at the same rate as the section header, and the one below it is just scooting back up to fill the space.

    Tapping the control causes the table view to rejigger itself and realize that the row isn’t actually gone.

    to try and work around this, try running the deletion in the next runloop, via a dispatch call, like:

    if ([self.tableView numberOfRowsInSection: fromIndexPath.section] == 0) {
        dispatch_async(dispatch_get_main_queue(), ^() {
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:fromIndexPath.section] withRowAnimation:UITableViewRowAnimationFade];
        });
    }
    

    this will cause the deletion to run on the main thread still, but allow the ‘moveRow’ and whatever call stack it happens to be in finish up its logic before the deletion call

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

Sidebar

Related Questions

I have a multi-dimensional multi-object array from a simplexml_import_dom() function call. A slice of
Let's say I have the following multi-line string: # Section ## Subsection ## Subsection
I have an array of documents, where each document have another simple one-dimensional array
I have a maven-multi project, when I create a new eclipse project from it
We have multi-part install that needs a reboot to continue. We added a RunOnce
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
I'm using 'rails3-jquery-autocomplete' gem, but it doesn't have multi column search, but there is
I have a multi-line string that I want to do an operation on each
I have a multi-table query, similar to this (simplified version) SELECT columns, count(table2.rev_id) As
I have a multi-user ASP.NET app running against SQL Server and want to have

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.