NSOutlineView problem
NSOutlineView problem
- Subject: NSOutlineView problem
- From: "peiyuan" <email@hidden>
- Date: Wed, 23 Jan 2008 18:23:54 +0800
Hi all,
I am now writeing a very simple example for NSOutlineView. I have already searched the mailing list. I follow the guide to do the example but failed.
Here is my main part of source codes:
===========================================
@interface device : NSObject {
NSString *deviceName;
}
- (NSString *)myDeviceName;
- (void)setMyDeviceName:(NSString *)newName;
=========================================================================
@interface machine : NSObject {
NSArray *myDevice;
NSString *name;
}
- (NSArray *)getMyDevice;
- (void)setMyDevice:(NSArray *)newDevice;
- (int)getMyDeviceNo;
- (NSString *)getMyName;
- (void)setMyName:(NSString *)newName;
===========================================
//I use init to init a sample data. There are two levels. Machine->Device
NSArray *myArray;
device device1,device2,device3,device4,device5;
machine mach1, mach2;
- (id) init {
self = [super init];
if (self != nil) {
[device1 retain];
[device2 retain];
[device3 retain];
[device4 retain];
[device5 retain];
[mach1 retain];
[mach2 retain];
device1 = [[device init] alloc];
[device1 setMyDeviceName:@"Device 1"];
device2 = [[device init] alloc];
[device2 setMyDeviceName:@"Device 2"];
device5 = [[device init] alloc];
[device5 setMyDeviceName:@"Device 5"];
mach1 = [[machine init] alloc];
[mach1 setMyName:@"machine 1"];
[mach1 setMyDevice:[NSArray arrayWithObjects:device1, device2, device5, nil]];
device3 = [[device init] alloc];
[device3 setMyDeviceName:@"Device 3"];
device4 = [[device init] alloc];
[device4 setMyDeviceName:@"Device 4"];
mach2 = [[machine init] alloc];
[mach2 setMyName:@"machine 2"];
[mach2 setMyDevice:[NSArray arrayWithObjects:device3, device4, nil]];
myArray = [NSArray arrayWithObjects:mach1, mach2, nil];
[myArray retain];
}
return self;
}
- (int)outlineView:(NSOutlineView *)ov numberOfChildrenOfItem:(id)item
{
[item retain];
if(item == nil)
{
return [myArray count];
}
return [item getMyDeviceNo];
}
- (BOOL)outlineView:(NSOutlineView *)ov isItemExpandable:(id)item {
return [item isKindOfClass:[machine class]] && [[item getMyDevice] count] > 0;
}
- (id)outlineView:(NSOutlineView *)ov child:(int)index ofItem:(id)item {
if (item == nil)
{
return [myArray objectAtIndex:index];
}
if ([item isKindOfClass:[machine class]])
{
return [[item getMyDevice] objectAtIndex:index];
}
NSLog(@"Return nil !!!");
return nil;
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
if ([item isKindOfClass:[machine class]])
{
return [item getMyName];
}
if ([item isKindOfClass:[device class]])
{
return [item myDeviceName];
}
return nil
}
==========================End of source==============
I compile the source. I can see the root level.
>machine 1
>machine 2
However, when I click the expand triangle, the child item doesn't show up. It is supposed to be:
>machine 1
>device 1
>device 2
>device 5
>machine 2
>device 3
>device 4
I look for the log.
It says
2008-01-23 18:06:46.303 olEx[1792] *** -[NSDocumentControllerMoreIVars count]: selector not recognized [self = 0x346220]
2008-01-23 18:06:46.303 olEx[1792] *** -[NSDocumentControllerMoreIVars count]: selector not recognized [self = 0x346220]
What is "NSDocumentControllerMoreIVars"? I think this should be "[myDevice count]". So, what happened? What did I do wrong?
Another question is that when should I use [xxxx retain], [xxxxx copy] and [xxxx release].
Please enlighten me.
Thank you.
Pei-Yuan
@KCodes
_______________________________________________
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