Re: NSTableView dummy question
Re: NSTableView dummy question
- Subject: Re: NSTableView dummy question
- From: Lorenzo <email@hidden>
- Date: Wed, 07 May 2003 11:49:51 +0200
Hi,
you should always give an identifier to each column in Interface Builder.
For example, for the two columns: "name" and "surname".
Then, in Project Builder, you should build an array containing the rows you
want to show in the list. Each row of the list is a NSDictionary* containing
two objects: "name" and "surname".
You first should define a myListArray as NSMutableArray in the class header
file (e.g.: MyList.h) this way:
//////////////////////////////////////////////////////////////////////
@interface MyList.h : NSObject
{
IBOutlet id theList;
NSMutableArray *myListArray ;
}
@end
//////////////////////////////////////////////////////////////////////
// Then in your main class file (e.g.: MyList.m) define:
//////////////////////////////////////////////////////////////////////
#import "MyList.h "
@implementation MyList.h
// For example, define an array with 3 rows in the awakeFromNib:
- (void)awakeFromNib
{
*myListArray = [NSMutableArray arrayWithCapacity:0];
[myListArray retain];
NSMutableDictionary *rowDict = [NSMutableDictionary dictionary];
[rowDict setObject:@"Robert" forKey:@"name"];
[rowDict setObject:@"Nash" forKey:@"surname"];
[myListArray addObject:rowDict];
[rowDict setObject:@"Ken" forKey:@"name"];
[rowDict setObject:@"Brown" forKey:@"surname"];
[myListArray addObject:rowDict];
[rowDict setObject:@"John" forKey:@"name"];
[rowDict setObject:@"Smith" forKey:@"surname"];
[myListArray addObject:rowDict];
}
// You need to release the listArray before closing the Nib file
- (void)dealloc
{
[myListArray release];
}
// This reports the number of the rows in the list
- (int) numberOfRowsInTableView: (NSTableView *) tableView
{
return [myListArray count];
}
// And this will tell your list object to show the items
// corresponding to the two columns of the list
- (id) tableView: (NSTableView *) tableView
objectValueForTableColumn: (NSTableColumn *) tableColumn
row: (int) row
{
NSDictionary *rowDict;
NSString *identifier = [tableColumn identifier];
rowDict = [myListArray objectAtIndex:row];
return [rowDict objectForKey:identifier];
}
@end
//////////////////////////////////////////////////////////////////////
I hope this helps
Best Regards
--
Lorenzo
email: email@hidden
>
From: Lloyd Dupont <email@hidden>
>
I'm doing my first attempts at using a NSTableView.
>
It's created in a nib file. (2 columns, with unknow identifier ..)
>
>
in awakeFromNib I also add a column to to the table with a given
>
identifier.
>
>
then, when my method:
>
- (id)tableView :(NSTableView *)tableView
>
objectValueForTableColumn:(NSTableColumn *)tableColumn
>
row:(int)row
>
>
>
is called, the 3rd called is never queried and the first 2 columns have
>
null identifiers.
>
could any one pinpoint me a simple NSTableView sample ?
>
>
thanks ....
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.