Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tableView:viewForTableColumn:row: not called

I am new to AppKit but not to UIKit.
I try to use an NSTableView and I want to populate programmatically.

So I implement

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
    return 1;
}

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
    return nil;
}

and I set my class as the delegate and datasource in Interface Builder.
numberOfRowsInTableView is called but tableView:viewForTableColumn:row: is not called.

If I add

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

this one is called.

If I understand, tableView:viewForTableColumn:row: is called for View-Based tables and tableView:objectValueForTableColumn:row: is called for Cell-Based tables.

How can I define that my table is View-Based ?

Edited: ok ... so the problem is I am using 10.6 and tableView:viewForTableColumn:row: is available since 10.7. So it means before 10.7 there is only Cell-Based tables ?

like image 645
Nicolas Hognon Avatar asked Jul 07 '12 12:07

Nicolas Hognon


1 Answers

In Interface Builder, in the Attributes inspector pane (Cmd-Opt-4), set the table view type to View Based. It is Cell Based by default.

You have to select the table view in either in the left-hand object view or by clicking on it in the editor. Notice that the first time you click on it in the editor, it will select the scroll view, so you will have to click on it a second time to get it to select the table view object.

I believe you need Xcode 4.3 or newer for the OS X 10.7 SDK, and hence view-based tables views, to be available.

like image 159
Monolo Avatar answered Nov 04 '22 10:11

Monolo