Re: NSTableCellView subclass layout from independent nib
Re: NSTableCellView subclass layout from independent nib
- Subject: Re: NSTableCellView subclass layout from independent nib
- From: Seth Willits <email@hidden>
- Date: Wed, 07 Mar 2012 23:02:18 -0800
On Mar 6, 2012, at 6:03 PM, Seth Willits wrote:
> Another possible solution is to use a class method on the cell view class which does loading from a nib. That method would then have some TableCellViewNibLoader class be File's Owner when loading the nib, and then the view inside the nib can actually be the table cell view instance which gets returned by the method. Possible, but also annoying.
<Note: Of course this email is resent now 2-days later than I wrote it… this mailing list isn't workin' too well at the moment :p >
Actually a separate class isn't needed. I had thought about it, thought it wasn't going to work, and now I realize it will work: You can just load the nib with no owner and scan the top level objects and find an instance of the cell view's class.
@implementation NSTableCellView (AraeliumAdditions)
+ (id)tableCellViewWithNibNamed:(NSString *)nibName;
{
NSView * view = nil;
NSArray * topLevelObjects = nil;
NSNib * nib = [[[NSNib alloc] initWithNibNamed:nibName bundle:nil] autorelease];
if (!nib || ![nib instantiateNibWithOwner:nil topLevelObjects:&topLevelObjects]) {
return nil;
}
for (id obj in topLevelObjects) {
if ([obj isKindOfClass:[self class]]) {
view = obj;
break;
}
}
return view;
}
@end
So, other than that this is different of any other nib loading I know of, it's useful and convenient.
--
Seth Willits
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden