Can't get NSTableView to display data.

Posted by Alberto on Stack Overflow See other posts from Stack Overflow or by Alberto
Published on 2009-12-04T11:34:25Z Indexed on 2010/03/21 22:01 UTC
Read the original article Hit count: 718

Hi! I see there are a lot of questions about this, but nothing helped me to get this work. I have a nib with a NSTableView with three columns (with the right identifiers set) and a class named ShortcutsTableController. In the nib I have a NSObject with class value ShortcutsTableController. I also connected the NSTableView to my controller as I usually do.

This is header ShortcutsTableController.h.

#import <Cocoa/Cocoa.h>


@interface ShortcutsTableController : NSObject <NSTableViewDataSource> {
    IBOutlet NSTableView *shortcutsTable;
    NSMutableArray *shortcutsList;
}

- (int) numberOfRowsInTableView: (NSTableView*) tableView;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;

@property (assign) IBOutlet NSTableView *shortcutsTable;
- (void)setUpTable;

@end

And this is the implementation file ShortcutsTableController.m.

#import "ShortcutsTableController.h"

@implementation ShortcutsTableController

@synthesize shortcutsTable;

- (void)setUpTable {

    shortcutsList = [[NSMutableArray alloc] init];

    NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:
                           @"blabla", @"nameColumn", 
                           @"Bla bla bla", @"shortcutColumn",
                           @"Ribla", @"actionColumn", nil];

    [shortcutsList addObject:dict1];

    [shortcutsTable setDataSource:self];
    [shortcutsTable reloadData];
}

-(int) numberOfRowsInTableView: (NSTableView *) tableView {
    return [shortcutsList count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row {

    if (row != -1)
    	return [[shortcutsList objectAtIndex:row] objectForKey:[tableColumn identifier]];

    return nil;
}

@end

But when i try to build nothing appears in the NSTableView. No errors, no warnings. Note that I call setUpTable from within the Delegate Class Method awakeFromNib.

Is there something I am doing wrong? Thank you for you help.

—Albé

UPDATE. Added lines @property (assign) IBOutlet NSTableView *shortcutsTable; in header and @synthesize shortcutsTable; in implementation. Nothing changes. :(

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about nstableview