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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:15:06+00:00 2026-05-25T11:15:06+00:00

I have an editable UITableView. While my user is re-arranging the cells, I want

  • 0

I have an editable UITableView. While my user is re-arranging the cells, I want to be able to update the tableview because I get a funny situation when I re-arrange the bottom cell and insert it into the middle. It create an unwanted effect because the bottom row is rounded and the middle row should not be. How can I prevent this from happening?

enter image description here

To achieve this look I had to set the backgroundView of each UITableViewCell. The top and bottom ones are using a separate image than ones in the middle.

UPDATED:

I am not sure if I am missing any cases, because the images still get messed up when re-ordering.

for (NSIndexPath* visibleIndexPath in tableView.indexPathsForVisibleRows) {
        UITableViewCell* cell = [tableView cellForRowAtIndexPath:visibleIndexPath];

        //Top moving to middle rows
        if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row != sectionRows - 1) {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablemiddle55@2x.png"];
        }
        //Top moving to bottom
        else if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row == sectionRows - 1) {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablebottom55@2x.png"];
        }
        //Top moving to top
        else if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row == 0) {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tabletop55@2x.png"];
        }
        //Middle moving to top
        else if (sourceIndexPath.row != 0 && sourceIndexPath.row != sectionRows -1 && proposedDestinationIndexPath.row == 0)
        {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tabletop55@2x.png"];
        }
        //Middle moving to bottom
        else if (sourceIndexPath.row != 0 && sourceIndexPath.row != sectionRows -1 && proposedDestinationIndexPath.row == sectionRows - 1)
        {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablebottom55@2x.png"];
        }
        //Middle moving to middle
        else if (sourceIndexPath.row != 0 && sourceIndexPath.row != sectionRows -1 && 
                 proposedDestinationIndexPath.row != sectionRows -1 && proposedDestinationIndexPath.row !=0)
        {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablemiddle55@2x.png"];
        }
        //Bottom moving to top
        else if (sourceIndexPath.row == sectionRows - 1 && proposedDestinationIndexPath.row == 0)
        {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tabletop@2x.png"];
        }
        //Bottom moving to middle
        else if (sourceIndexPath.row == sectionRows - 1 && proposedDestinationIndexPath.row != 0 && proposedDestinationIndexPath.row != sectionRows - 1)
        {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablemiddle@2x.png"];
        }
        //Bottom moving to bottom
        else if (sourceIndexPath.row == sectionRows - 1 && proposedDestinationIndexPath.row == sectionRows - 1)
        {
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablebottom@2x.png"];
        }
    }
  • 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-25T11:15:07+00:00Added an answer on May 25, 2026 at 11:15 am

    The code you posted is mostly wrong because of the for {}. As it stands right now, you do something like “if the destination is such and the source is such, modify all the currently visible cells”. But anyway, this is not the main problem.

    I must say, I’ve played a lot of time with the method tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: before even attempting to answer this question. Now I feel more confident to write it.

    For starters, using this method in conjunction with tableView:cellForRowAtIndexPath: is not a good choice if you don’t know what’s happening. Simply put, even though the cells have shifted for the animation, the changes don’t really affect the tableView until the user stops dragging the cell.

    For example, let’s say that you have the cell at index 0 with the title @"Hello", and the next cell with @"World", if you start dragging the first cell downwards, the animation will move the cell “Hello” one row upwards, but calling tableView:cellForRowAtIndexPath for the row at index 0 will always return the “Hello” cell. The tableView is unaffected until the tableView reorder ends, everything else is just eye-candy.

    So, to answer your question, and to swap the images on the fly (as soon as the user moves the cell), you should do the following, for example, for the first row:

    //Top moving to middle rows
    if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row != 0)
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:sourceIndexPath.section]];
        ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablemiddle55"];
    }
    

    One the user drags the row 0 downwards, it tells the row at 1 to swap its background to the top, as he will become the new top row. Similar cases must be considered for the bottom row, or middle row becoming the first one. Also, the for {} with the visible cells is not necessary in this case.

    Edit: Okay, I managed to make ALL the cases, it has some weird things here and there, but it works most of the time. The code here just changes the detailLabel to “First”/”Middle”/”Last”, but that should be easy to change with a Find&Replace.

    - (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
    {
        //NSLog(@"%d -> %d (proposed)", sourceIndexPath.row, proposedDestinationIndexPath.row);
    
        NSInteger lastRow = [arrayWithContent count]-1;
    
        // Adjust the row being moved
        if (proposedDestinationIndexPath.row == 0)
            [tableView cellForRowAtIndexPath:sourceIndexPath].detailTextLabel.text = @"First";
        else if (proposedDestinationIndexPath.row == lastRow)
            [tableView cellForRowAtIndexPath:sourceIndexPath].detailTextLabel.text = @"Last";
        else
            [tableView cellForRowAtIndexPath:sourceIndexPath].detailTextLabel.text = @"Middle";
    
        // Top -> Middle
        if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row == 1)
        {
            NSLog(@"Top -> Middle");
            [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]].detailTextLabel.text = @"First";
        }
        // Top -> Top (user is screwing around)
        else if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row == 0)
        {
            NSLog(@"Top -> Top");
            [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]].detailTextLabel.text = @"Middle";
        }
        // Middle -> Top
        else if (sourceIndexPath.row > 0 && proposedDestinationIndexPath.row == 0)
        {
            NSLog(@"Middle -> Top");
            [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].detailTextLabel.text = @"Middle";
        }
        // Middle -> Bottom
        else if (sourceIndexPath.row < lastRow && proposedDestinationIndexPath.row == lastRow)
        {
            NSLog(@"Middle -> Bottom");
            [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:lastRow inSection:0]].detailTextLabel.text = @"Middle";
        }
        // Bottom -> Middle
        else if (sourceIndexPath.row == lastRow && proposedDestinationIndexPath.row == lastRow-1)
        {
            NSLog(@"Bottom -> Middle");
            [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:(lastRow-1) inSection:0]].detailTextLabel.text = @"Last";
        }
        // Bottom -> Bottom (user is screwing around, AGAIN)
        else if (sourceIndexPath.row == lastRow && proposedDestinationIndexPath.row == lastRow)
        {
            NSLog(@"Bottom -> Bottom");
            [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:(lastRow-1) inSection:0]].detailTextLabel.text = @"Middle";
        }
        // Middle -> Top -> Middle (ugh)
        else if (sourceIndexPath.row > 0 && sourceIndexPath.row < lastRow && proposedDestinationIndexPath.row == 1)
        {
            NSLog(@"Middle -> Top -> Middle");
            [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].detailTextLabel.text = @"First";
        }
        // Middle -> Bottom -> Middle (ugh x2)
        else if (sourceIndexPath.row > 0 && sourceIndexPath.row < lastRow && proposedDestinationIndexPath.row == lastRow-1)
        {
            NSLog(@"Middle -> Bottom -> Middle");
            [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:lastRow inSection:0]].detailTextLabel.text = @"Last";
        }
    
        return proposedDestinationIndexPath;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Listbox where all cells are editable. While the user is typing
I have a UITableView that is editable. I am commiting changes via: - (void)tableView:(UITableView
I have an editable UITableView. By default the user can swipe and the Delete
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have a simple table view which is editable. All I need the user
I have a UITableViewController where the user should be able to edit the items.
I have 4 editable uitextviews, user can set its font font color etc. Now
I have an editable WPF ComboBox with TextSearchEnabled. I need to force the user's
I need some help. I have a UITableView that has cells that hold the
I have a tableView that I want to allow editing and delete rows. I

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.