[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Introduce me to NSTableView

From: Christopher Culver
Subject: Introduce me to NSTableView
Date: Fri, 6 Jun 2003 03:03:25 +0300

I'm trying to implement two NSTableViews for my GSCharmap application. One, the actual character map itself, will be somewhat complex and I'll worry about that later. First I'm trying to do the category selection. It is a single-column table (is there any better way to do it?) listing all of the Unicode blocks (e.g. Greek Extended, Katakana, etc) so the user, by double-clicking on a category, can jump straight to that particular part of the character. So, the data source should be pretty easy, right?

NSArray *blocks;
blocks = [NSArray initWithObjects: @"Basic Latin", @"Latin-1 Supplement",...nil]

So much for the NSArray. My problem lies with creating the data source class and initialising a table.

@implementation GSCharmapBlocks : NSObject
       NSArray *blocks;
- (int) numberOfRowsInTableView:(NSTableView *)aTableView
      return [blocks count];

- (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:
(NSTableColumn *)aTableColumn row:(int)rowIndex
        return [blocks objectAtIndex:rowIndex];

This seems to be the stereotypical implementation for a NSTableView data source. Having create the data source, what steps must I take to initialise the table? So far, I have this:

hbox = AUTORELEASE ([GSHbox new]);
blocksTable = AUTORELEASE ([NSTableView new]);
blocksDataSource = [GSCharmapBlocks new];
[blocksTable setDataSource: blocksDataSource];
[blocksTable setRowHeight: 40];
[hbox addView: blocksTable];

This does not, however, result in a visible NSTableView in my application window. What more must I do? Must I manually add a column to the table view? If so, how?

NSTableView seems to be one of the more difficult GUI objects for Openstep newbies (in Cocoa forums I see a lot of puzzlement about it). It'd be really cool to have an NSTableView tutorial for GNUstep.

Christopher Culver

reply via email to

[Prev in Thread] Current Thread [Next in Thread]