Hi all,

I'm trying to use an NSTableView for the first time. I've got a four- column table view set up in IB, and class files for the dataSource as follows:

.h:
@interface ShowResults : NSObject {
        IBOutlet id theTable;
        
        @private
        NSMutableArray *finalData;
        NSMutableArray *currentData;
}

- (IBAction)fetchResults:(id)sender;
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn: (NSTableColumn *)aTableColumn row:(int)rowIndex; - (void)tableView:(NSTableView *)aTableView setObjectValue:anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;
- (int)numberOfRowsInTableView:(NSTableView *)aTableView;

@end

.m:
@implementation FetchHighscores

- (IBAction)fetchResults:(id)sender
{
finalData = [NSMutableArray arrayWithCapacity:4]; // To prevent it being (null) NSString *string = @"1,1,1 2,2,2 3,3,3 4,5,6 7,3,4" // etc. Loaded from an external source.
        NSArray *components = [results componentsSeparatedByString:@"\n"];
NSArray *template = [NSArray arrayWithObjects:@"Col1", @"Col2", @"Col3", @"Col4", nil];
        int loops = [components count];
        int loop;
        for (loop = 0; loop < loops; loop++)
        {
                currentData = [NSMutableArray arrayWithCapacity:4];
                [currentData addObject:@"0"];
[currentData addObjectsFromArray:[[scores objectAtIndex:loop] componentsSeparatedByString:@","]]; while ([currentData count] < 4) // External source isn't entirely consistent. This is just a placeholder.
                {
                        [currentData addObject:@"0"];
                }
NSDictionary *dict = [NSDictionary dictionaryWithObjects:currentData forKeys:template];
                [finalScores insertObject:dict atIndex:loop];
        }
        [theTable reloadData];
}


// Code below is modified from Apple's website.
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
                        row:(int)rowIndex
{
        id theRecord, theValue;
        
    NSParameterAssert(rowIndex >= 0 && rowIndex < [finalData count]);
    theRecord = [finalData objectAtIndex:rowIndex]; // Error
theValue = [theRecord objectForKey:[aTableColumn identifier]]; // Error
    return theValue;
}

- (void)tableView:(NSTableView *)aTableView
   setObjectValue:anObject
   forTableColumn:(NSTableColumn *)aTableColumn
                          row:(int)rowIndex
{
    id theRecord;
        
    NSParameterAssert(rowIndex >= 0 && rowIndex < [finalData count]);
    theRecord = [finalData objectAtIndex:rowIndex];
    [theRecord setObject:anObject forKey:[aTableColumn identifier]];
    return;
}

- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
        return [finalData count];
}

@end

I'm getting strange errors. In the console, I get:
*** -[NSRectSet objectAtIndex:]: unrecognized selector sent to instance 0x1516c220

But sometimes I get a different error: the NSParameterAssert isn't satisfied.

What needs changing?

Thanks.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to