• 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 with C++ classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOutlineView with C++ classes


  • Subject: Re: NSOutlineView with C++ classes
  • From: Corbin Dunn <email@hidden>
  • Date: Fri, 23 Sep 2005 16:10:08 -0700

returned. Casting Group to id or objc_object won't
work because the view (apparently) tries to talk to
the object returned as though it were an NSObject.

Unfortunatly, that is true (see my reply to Jerry for some notes on that).



My 'solution' has been to use instances of an NSObject based class, Wrapper in this function. Wrapper know's nothing of C++; it just holds a pointer to the Group class.

I would create a lightweight "node" class that simply has the C++ pointer, and a children array (which is an array of more of those nodes). You can probably extend your class. Here are some quick modifications (typed in Mail -- this is just conceptual):




#import <Cocoa/Cocoa.h> @class Group;

@interface Wrapper : NSObject {
id	node;
Group *realItem;
NSArray *children;
}
-(void)setNode:(Group*)n;
-(id)node;

@end

#import "Wrapper.h"

@implementation Wrapper


- (void)initWithGroupNode:(Group *)n { ..super stuff; realItem = n; }


- (void)loadChildren {
// be sure to release children in dealloc
if (children == nil) {
children = [[NSMutableArray alloc] init];
for (int i = 0; i < groupNode->count; i++)
[children addObject:[[[Wrapper alloc] initWithNode:groupNode- >getNode(i)]] autorelease];
}
}


@end

I can then pass Wrapper back as an id and all my code
works:

- (id)outlineView:(NSOutlineView *)ov child:(int)index
ofItem:(id)item {
if (item){

[item loadChildren]; return [[item children] objectAtIndex:index];

}

if (rootWrapper == nil) { rootWrapper = [[Wrapper alloc] initWithNode:root]; [rootWrapper loadChildren]; } return [[rootWrapper children] objectAtIndex:index];

}


Does this make sense? It is just a quick mockup, but should be easy to understand. You can also clean it up (ie: make the ivars private, and add accessors to them. the children accessor can do the loadChildren call, etc.)

--corbin


_______________________________________________ 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
References: 
 >NSOutlineView with C++ classes (From: Daniel Price <email@hidden>)

  • Prev by Date: Re: NSOutlineView with C++ classes
  • Next by Date: localization Q
  • Previous by thread: Re: NSOutlineView with C++ classes
  • Next by thread: How do I upload data to a FTP server?
  • Index(es):
    • Date
    • Thread