1

I found some guidelines for creating something similar for UITableView, but I'm interested in how it's done for Mac OS X.

I have done the following:

  1. I have an NSTableView with two columns. For the first row, the template TableCellView "Image & Text Table Cell View" from Object Library works just fine. For the second row, I would like to have something more complicated which requires a custom TableViewCell.

  2. a) I created a xib file where I layed out the needed objects from Object Library. b) I subclassed NSTableViewCell, connected my xib file to this class in Identity Inspector, and connected the IBOutlets for the stuff in my xib.

  3. I then came back to my NSTableView, drag&dropped the "Text Table Cell View", got rid of the text field, and in the Identity Inspector set up the custom class to be my own subclass of NSTableViewCell.

  4. in my

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

method, I take the identifier

NSString* identifier = [tableColumn identifier];

and if it's equal to my second column identifier, I need to return an instance of my subclass.

But how do I do that? I couldn't find something similar to this:

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];

I'm using a view-based NSTableView. I'm starting to suspect I am doing it all wrong and there's a better way. Any help greatly appreciated.

nik4emniy
  • 143
  • 1
  • 9
  • 2
    fist you need to `-registerNib:forIdentifier:`, then you just need the `-makeViewWithIdentifier:owner:`... here is the guide for you: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/#//apple_ref/occ/instm/NSTableView – holex Mar 23 '15 at 14:32
  • Thank you, that seems to have worked! Appreciate it. – nik4emniy Mar 23 '15 at 14:54

0 Answers0