Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment