NSTableView makeViewWithIdentifier via Tips

I have a similar Cocoa question - View-based NSTableView using a single cell in multiple tables , reinforced Apple's own docs for makeViewWithIdentifier:owner:

"Typically, the identifier is associated with an external NIB in Interface Builder, and the table view automatically creates an NIB instance with the owner provided."

This seems to mean that you should be able to store the NSTableCellView in a separate tip from the nib containing the NSTableView . However, in my experiment, I could only ever get the cells that are in the table I'm calling. Ie, if I cut and paste my cell into a new .xib file, tableview will no longer be able to find it. What am I doing wrong, or is it really impossible, and am I somehow reading Apple documents incorrectly?

+8
cocoa interface-builder xib nib nstableview
source share
2 answers

Use - (void)registerNib:(NSNib *)nib forIdentifier:(NSString *)identifier to register the tip to be used with the cell identifier.

If it does not work, you are probably registering nib after the data in the View table has been loaded. Use the [tableView reloadData] afterword to make sure this is not a time issue.

+5
source share

I just ran into this problem and I think that you cannot use makeViewWithIdentifier: owner: when you use dedicated Nib to populate View based tables.

The problem is with file owners (i.e., view controllers). makeViewWithIdentifier: owner: seems to be intended for use with the self as the owner for simple user views.

Typically, if you have a separate tip for a custom view with outputs, you will also need a separate view controller. Otherwise, if your custom view has a way out and many custom views are displayed in the table, what conclusion do you feel about the table owner’s own owner?

So, in my test, I have AppDelegate as the delegate / data source of Table View. I have CellView.xib and CellViewController.h / .m with interface outputs. Then in my method tableView: viewForTableColumn: string: I have this code:

 SSCellViewController *vc = [[SSCellViewController alloc] initWithNibName:@"CellView" bundle:nil]; return vc.view; 

What you lose is cell reuse, which happens automatically with makeViewWithIdentifier: owner :. To implement this yourself, you will also probably have to deal with managing many of the created view controllers.

I may still be missing something as I come to the development of OS X after many years of working with iOS.

+3
source share

All Articles