• 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
Re: nsoutlineview crashes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nsoutlineview crashes


  • Subject: Re: nsoutlineview crashes
  • From: Corbin Dunn <email@hidden>
  • Date: Fri, 22 Feb 2008 08:15:29 -0800


On Feb 22, 2008, at 6:51 AM, Julius Eckert wrote:

Hi,

i am implementing a datasource for an nsoutlineview to represent the
contents of a simple tree-structure defined by the following class
(simplified):

@interface TBCatalogNode : NSObject {
   NSMutableArray* children;
}
@property (readonly, retain) NSMutableArray* children;

(the array children is created by the constructor is definately never nil)

my data source looks like this:

-(CatalogRepresentation*) initWithNode:(TBCatalogNode*)rootNode {
   if (self = [super init]) {
       root = [rootNode retain];
   }
   return self;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index
ofItem:(id)item {
   TBCatalogNode* objItem = (item == nil) ? root : item;
   return [[[objItem children] objectAtIndex:index] retain];
}

You are responsible for maintaining the life of the objects, not the outline view. it does not retain/release the objects. It is incorrect to have the last retain in there.




- (NSInteger)outlineView:(NSOutlineView *)outlineView
numberOfChildrenOfItem:(id)item {
   return (item == nil) ? [[root children] count] : [[item children]
count];
}

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable: (id)item {
return ([self outlineView:outlineView numberOfChildrenOfItem:item] > 0);
}


- (id)outlineView:(NSOutlineView *)outlineView
objectValueForTableColumn:(NSTableColumn *)tableColumn byItem: (id)item {
TBCatalogNode* objItem = (item == nil) ? root : item;
return [[[objItem preset] info] objectForKey:@"ID"]; // this line gets
a string from a nsdictionary
}


This code works perfect with the garbage collection activated. when i
disable the gc it is working just at the begining, it shows the first level
under the root. when i click to expand an item it crashes -> debugger is
telling me at numberOfChildrenOfItem: - function.
I dont know what in the background is going on as I am pretty new to OSX. I
guess it is about some memory management, threading ?! I tried to retain
nearly everything, and I am running out of ideas.

Your model, the TBCatalogNode, needs to retain all the children (which it probably does). You are probably doing something wrong when inserting children into your model.


corbin
_______________________________________________

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


References: 
 >nsoutlineview crashes (From: "Julius Eckert" <email@hidden>)

  • Prev by Date: Re: NSInvocation question
  • Next by Date: Re: Private Methods
  • Previous by thread: nsoutlineview crashes
  • Next by thread: Re: Listener related crashing bug releasing subviews of a custom view
  • Index(es):
    • Date
    • Thread