Skip to content

Instantly share code, notes, and snippets.

@kluivers
Created December 27, 2012 12:33
Show Gist options
  • Select an option

  • Save kluivers/4388037 to your computer and use it in GitHub Desktop.

Select an option

Save kluivers/4388037 to your computer and use it in GitHub Desktop.
Load a NSTableCellView from a NIB
@interface NSTableCellView (JKNibLoading)
+ (instancetype) tableCellViewWithNibNamed:(NSString *)nibName owner:(id)owner;
@end
@implementation NSTableCellView (JKNibLoading)
+ (instancetype) tableCellViewWithNibNamed:(NSString *)nibName owner:(id)owner
{
NSTableCellView *view = nil;
NSArray * topLevelObjects = nil;
NSNib * nib = [[NSNib alloc] initWithNibNamed:nibName bundle:nil];
if (!nib || ![nib instantiateNibWithOwner:owner topLevelObjects:&topLevelObjects]) {
return nil;
}
for (id obj in topLevelObjects) {
if ([obj isKindOfClass:[self class]]) {
view = obj;
break;
}
}
return view;
}
@end
@tongds
Copy link
Copy Markdown

tongds commented Jul 5, 2021

This one works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment