Re: Bug with NSTreeController
Re: Bug with NSTreeController
- Subject: Re: Bug with NSTreeController
- From: Frank Illenberger <email@hidden>
- Date: Mon, 13 Mar 2006 21:20:35 +0100
I was struggeling for half a year with all the problems and bugs in
NSTreeController until I decided to implement my own tree controller
for my project. NSTreeController seems to be very sensitive to the
timing and ordering of the change notifications so that it often gets
a problem when they derive from undo/redo or from timer calls. My bug
reports to Apple of the last four months did not lead to an update of
NSTreeController. So this really became a serious issue for our
project and I had no other choice than to implement my own
controller. And I was very suprised to see that it only took two days
to completely implement it. Compared to the endless days of trying to
work around the bugs in NSTreeController, it is sad that I started it
so late in the game. My tree controller is implemented as a classic
data source for an outline view or browser. It can have a set or an
array of root objects that are fed via bindings, it uses the same
childKeyPath/isLeafKeyPath concept as NSTreeController. Like the
Apple's implementation, it builds a parallel tree structure of its
own node objects that observe the original ones for the displayed
attributes. I also observe the key paths of the active sort
descriptos so that I immediately get an autosorting behavior. In
addition to NSTreeController, my nodes know their parent nodes and
the tree controller can map the original observed objects back to the
tree nodes. Using that I am able to implement the features
setSelectedObjects: or uncoverObjects: that Apple's implementation
lacks. It also easy to implement filtering with predicates that takes
into account that the whole path to a filtered objects must be visible.
Apple's basic idea of the tree controller is brilliant but its
implementation is closed and buggy. So If you heavily rely on the
handling of trees, consider to implement your own tree controller or
start a community that does so. It is not hard to do and it enables
you to implement fancy features on top of it. When my application
will be finished and I have some spare time again I will be happy to
share my code with you.
Frank
I starting getting crashes with NSTreeController. My application
started crashing constently with *** -[NSCFArray objectAtIndex:]:
index (x) beyond bounds (x). After some searching I came across the
following link
http://www.cocoadev.com/index.pl?search=NSTreeControllerBug
What you have to do is to use a subclass of NSTreeController and
overwrite the setContent methods as follows.
- (void)setContent:(id)content
{
if(![content isEqual:[self content]])
{
NSArray *paths = [[self selectionIndexPaths] retain];
[super setContent:nil];
[super setContent:content];
[self setSelectionIndexPaths:paths];
[paths release];
}
}
The site seems to suggest that this bug was isolated to 10.4.3, but I
am using 10.4.5 and was experiencing the same problem. I was
wondering if this is an actual bug, or if I am doing something
wrong. I tried my best to debug this further, without much success.
After I implemented the suggested solution, the application did not
crash anymore.
Thanks for any feedback.
Alexander Hartner
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden