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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:44:49+00:00 2026-06-11T09:44:49+00:00

I have a view based NSTableView that I sometimes filter using NSPredicate . Is

  • 0

I have a view based NSTableView that I sometimes filter using NSPredicate. Is there any way to animate the items being removed/added/reordered throughout the tableview to have the same effect as beginUpdates, endUpdates and insertRowsAtIndexes:withAnimation, etc?

I’ve explored ways such as manually filtering out my array but my attempts proved to be futile so now I am wondering if there is a better (or built in way) to do this. I have wondered if NSArrayController does this automatically but I don’t think it does.

  • 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-11T09:44:51+00:00Added an answer on June 11, 2026 at 9:44 am

    I’ve written code to do this myself – given ‘before’ and ‘after’ arrays, compute the required parameters to insertRowsAtIndexPaths:, deleteRowsAtIndexPaths:, etc. The code is a bit fiddly so probably has bugs – use at your discretion!

    @interface NSArray (ArrayDifference)
      - (void) computeDifferenceTo:(NSArray *)newArray returningAdded:(NSMutableArray **)rowsAdded andDeleted:(NSMutableArray **)rowsDeleted;
    @end
    
    @implementation NSArray (ArrayDifference)
    
    // Given two arrays that are expected have items added or removed but not re-ordered, compute the differences
    // in a way usable for UITable insertRows and deleteRows
    - (void) computeDifferenceTo:(NSArray *)newArray returningAdded:(NSMutableArray **)rowsAdded andDeleted:(NSMutableArray **)rowsDeleted
    {
      NSArray *oldArray = self;
      *rowsAdded = [[[NSMutableArray alloc] init] autorelease];
      *rowsDeleted = [[[NSMutableArray alloc] init] autorelease];
    
      NSUInteger oldCount = [oldArray count];
      NSUInteger newCount = [newArray count];
      // Step through the two arrays
      NSInteger oldIndex = 0, newIndex=0;
      for (; newIndex < newCount && oldIndex < oldCount; )
      {
        id newItem = [newArray objectAtIndex:newIndex];
        id oldItem = [oldArray objectAtIndex:oldIndex];
        // If the two objects match, we step forward on both sides
        if (newItem == oldItem) {
            ++newIndex;
            ++oldIndex;
        }
        else {
            // Look for the old item to appear later in the new array, which would mean we have to add the rows in between
            NSRange range = { newIndex+1, newCount - newIndex-1 };
            NSUInteger foundIndex = [newArray indexOfObject:oldItem inRange:range];
            if (foundIndex != NSNotFound)
                for (; newIndex < foundIndex; ++newIndex)
                    [*rowsAdded addObject:[NSIndexPath indexPathForRow:newIndex inSection:0]];
            else {
                // Look for the new item to appear later in the old array, which would mean we have to remove the rows in between
                NSRange range = { oldIndex+1, oldCount - oldIndex-1 };
                NSUInteger foundIndex = [oldArray indexOfObject:newItem inRange:range];
                if (foundIndex != NSNotFound)
                    for (; oldIndex < foundIndex; ++oldIndex)
                        [*rowsDeleted addObject:[NSIndexPath indexPathForRow:oldIndex inSection:0]];
                else {
                    // Old item must be removed and new item added, then we carry on
                    [*rowsAdded addObject:[NSIndexPath indexPathForRow:newIndex++ inSection:0]];
                    [*rowsDeleted addObject:[NSIndexPath indexPathForRow:oldIndex++ inSection:0]];
                }
            }
        }
      }
      // Once the loop is finished, add in what's left in the new array and remove what is left in the old array
      for (; newIndex < newCount; ++newIndex)
        [*rowsAdded addObject:[NSIndexPath indexPathForRow:newIndex inSection:0]];
      for (; oldIndex < oldCount; ++oldIndex)
        [*rowsDeleted addObject:[NSIndexPath indexPathForRow:oldIndex inSection:0]];
    }
    
    @end
    

    Then you call it like this:

        NSMutableArray *rowsAdded=nil, *rowsDeleted=nil;
        [myArray computeDifferenceTo:newArray returningAdded:&rowsAdded andDeleted:&rowsDeleted];
        [myTableView beginUpdates];
        [myTableView insertRowsAtIndexPaths:rowsAdded withRowAnimation:UITableViewRowAnimationBottom];
        [myTableView deleteRowsAtIndexPaths:rowsDeleted withRowAnimation:UITableViewRowAnimationFade];
        [myTableView endUpdates];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view-based NSTableView that is populated through bindings. My textFields & imageViews
I have a view-based NSTableView that usually has one column in it. However, at
I have a view-based NSTableView that I'm backing with an `NSMutableArray . Periodically I
I have a view controller based app that contains several views that I display/hide
I have a view-based NSTableView populated custom NSTabelCellView subclass, which are the lowest objects
I have a view-based app that just does one thing : show a array
I have a view-based application, and in one of the subviews there is a
I have a View-based app. The first view that is loaded has a button
I have a view based app that works well. (In other words, I'm not
I have an application with a view-based NSTableView in it. Inside this table view,

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.