View NSTableView based on view from XIB?

Is it possible to have a separate XIB file for view- NSTableCellViewbased NSTableView? Maybe with help NSViewController?

+3
source share
1 answer

Yes, that seems possible.

From the Apple documentation:

To function, a software-based view-based table must implement the following:

...

. - (NSView *) tableView: viewForTableColumn: string: a method that is defined by the NSTableViewDelegate protocol. This method provides the table with a view to display as a cell for a specific column and row, and also populates this cell with the appropriate data.

, NSView ( ) . , . , , :

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Assume you have a XIB called View.xib
    [NSBundle loadNibNamed:@"View" owner:self];

    // And you have an IBOutlet to your NSTableView (that view based) called tView
    [tView reloadData];
}

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

- (NSView *)tableView:(NSTableView *)tableView
   viewForTableColumn:(NSTableColumn *)tableColumn
                  row:(NSInteger)row {


    // Assume your class has an IBOutlet called contentOfTableView, 
    // your class is File Owner of the View.xib and you connected the outlet.
    return contentOfTableView;

}

, . , . !

+2

All Articles