• 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
Insertion bug in NSTreeController?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Insertion bug in NSTreeController?


  • Subject: Insertion bug in NSTreeController?
  • From: Rob Keniger <email@hidden>
  • Date: Thu, 4 Dec 2008 12:04:19 +1000

Hi all,
I have a very simple model object that I want to use as a tree node in an NSTreeNode hierarchy. It has a NSMutableArray that I am using as the children key for NSTreeController.


I'm having a problem when I call - insertObject:atArrangedObjectIndexPath: on NSTreeController where the new object is not inserted at the correct location in the model object's hierarchy if the indexPath has a length greater than 1 (i.e. for any levels lower than the root level).

What happens is that the new item is always added as the last item in the array of child objects, no matter what index path I set it to.

So if I have this hierarchy:

Item 1
	Sub Item 1
	Sub Item 2
Item 2

And I call -insertObject:atArrangedObjectIndexPath: with an indexPath of [0][0], the tree should look like this:

Item 1
	New Item
	Sub Item 1
	Sub Item 2
Item 2

What's weird is that the new item is added in the correct location in the NSTreeController's arrangedObjects hierarchy of NSTreeNodes, but the underlying children array always adds the item at the end of the array:

Item 1
	Sub Item 1
	Sub Item 2
	New Item
Item 2

The backtrace at insertion time is interesting because it's clear that the private class NSTreeControllerTreeNode is calling - insertObject:inSubNodesAtIndex: which is then calling the -addObject: method of NSKeyValueNotifyingMutableArray when it should really be called -insertObject:atIndex:, but of course I have no control over that.

#0 -[Item insertObject:inChildrenAtIndex:]
#1 -[NSKeyValueFastMutableArray insertObject:atIndex:]
#2 -[NSKeyValueFastMutableArray addObject:]
#3 -[NSKeyValueNotifyingMutableArray addObject:]
#4 -[NSTreeControllerTreeNode insertObject:inSubNodesAtIndex:]
#5 -[NSKeyValueFastMutableArray insertObject:atIndex:]
#6 -[NSTreeController _insertObject:atArrangedObjectIndexPath:objectHandler:]
#7 -[NSTreeController insertObject:atArrangedObjectIndexPath:]
#8 -[ItemTreeController add:]


Is this a bug, or am I doing something wrong in my implementation?

You can see the problem in action in this project:

http://menumachine.com/quickies/TreeControllerFail.zip

The project uses a very simple model object with an NSMutableArray to hold the children of the object, and a subclass of NSTreeController that modifies the -add: method.

To see the problem:
1. Disclose the second level of both outline views
2. Select SubItem 0
3. click the Add Item button.
Any help would be much appreciated, I have spent a long time trying to work out what I might be doing wrong.


--
Rob Keniger



_______________________________________________

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: Re: Trouble with array controller -> array
  • Next by Date: Re: NSSavePanel mishandling extensions
  • Previous by thread: Re: Adding an application to the login items
  • Next by thread: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
  • Index(es):
    • Date
    • Thread