Question

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. :(

Was it helpful?

Solution

Based on the results of your NSLog statement in setUpTable:, you don't have your IBOutlet set up. Perhaps you did, but it somehow got lost (undo, overwrite, accidentally deleted it, etc). You'll need to go back to Interface Builder and re-establish the connection between ShortcutsTableController and the NSTableView in the xib.

OTHER TIPS

How many objects in shortcutsList?

Try to iterate through the dictionary anywhere else but the datasource methods to see if its displaying data correctly.

Also, have you set the controller as the datasource of that table in IB or manually in your awakeFromNib?

Are you calling [table reloadData] when you update shortcutList?

Try adding

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

to your code where 1 is the number of sections you have in your table

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top