2
votes

To be able to customize some of my NSTableview's behaviour, I created this new class to act as a controller for the table view.

@interface aTableViewController : NSObject<NSTableViewDelegate>

@end
@implementation aTableViewController    
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
    return 1;
}

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
    return @"something";
}

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{}

@end

The existing table view is binded to an NSArrayController to get data, works beautifully. I used an NSObject to reference to this aTableViewController in the IB, and connect the table view's delegate to this controller object. However, none of these delegates ever got called.

Any suggestions? Thanks!

2
What do you mean by " I used an NSObject to reference to this aTableViewController in the IB"? Did you drag out a blue cube and change its class to aTableViewController?rdelmar
@rdelmar yes, that's exactly what I did.Robert Kang

2 Answers

3
votes

My NSTableview is view-based instead of cellbased. That's why tableView:willDisplayCell:forTableColumn:row: never gets called

For view-based tableview, you can use

func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
}
1
votes

I see several problems with what you posted. In the @interface code you have aTableViewController, whereas in your @implementation code you have WorkspaceTableViewController. Is one of these a typo or is this 2 different classes?

Secondly, the methods you have in the controller are data source methods not delegate methods. If you are using bindings to populate your table, then these methods aren't called.