• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSOutlineView -reloadItem: vs insertItemsAtIndexes:inParent:withAnimation:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSOutlineView -reloadItem: vs insertItemsAtIndexes:inParent:withAnimation:


  • Subject: NSOutlineView -reloadItem: vs insertItemsAtIndexes:inParent:withAnimation:
  • From: Chris Devereux <email@hidden>
  • Date: Thu, 24 Jan 2013 01:37:20 +0000

Hi there,

I've been having intermittent unexplained out of bounds errors when
inserting new items into an NSOutlineView.

Here's a snippet from my controller's update method (triggered by a KVO
notification) that should explains the sort of problem I've been having.
This class it's from is the delegate and data source for the outline view.

    if ([insertedSet count] > 0) {
        NSIndexSet* insertedIndexes = [newContentArray
indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
            return [insertedSet containsObject:obj];
        }];

        NSLog(@"%d", (int)[self outlineView:_outlineView
numberOfChildrenOfItem:parentItem]); // => 1
        NSLog(@"%@", insertedIndexes); // => { 1 }

        [_outlineView insertItemsAtIndexes:insertedIndexes inParent:
parentItem withAnimation:NSTableViewAnimationSlideDown]; // => Exception
here
    }

The exception I'm getting is "NSOutlineView error inserting child indexes
<NSIndexSet: 0x1018e3bf0>[number of indexes: 1 (in 1 ranges), indexes: (1)]
in parent 0x101850920 (which has 0 children)".

So it looks like NSOutlineView's internal state is somehow getting out of
sync with my controller class.

I think I have it tracked down to the fact that I didn't want the first
bunch of content displayed to animate in, so I had the following at the
beginning of the method:

if (_flags.isSettingContent) {

    [_outlineView reloadItem:parentItem];

    return;
}


Replacing it with:

if (_flags.isSettingContent) {

    [_outlineView insertItemsAtIndexes:insertedIndexes inParent:parentItem
 withAnimation:NSTableViewAnimationEffectNone];

    return;
}


seems to fix the problem. Problem is, I'm not sure why it fixes it... A
simple test case didn't seem to reproduce the issue.

Has anyone noticed any differences in behaviour between these two ways of
updating an outline view?

Thanks
Chris
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: new to Cocoa/Objective-c: many points of confusion
  • Next by Date: -mouseDragged: invoked when it should not (and without mouseDown)
  • Previous by thread: Re: new to Cocoa/Objective-c: many points of confusion
  • Next by thread: -mouseDragged: invoked when it should not (and without mouseDown)
  • Index(es):
    • Date
    • Thread