• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
What's the best way to access top level objects loaded from a nib?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What's the best way to access top level objects loaded from a nib?


  • Subject: What's the best way to access top level objects loaded from a nib?
  • From: Ken Tozier <email@hidden>
  • Date: Mon, 16 Mar 2009 07:12:22 -0400

Hi

I'm building up some complex custom views from other custom views etc, etc and am able to load nibs programatically and get the list of top level objects, but it just seems awkward to have to iterate over the list of items and do class tests to determine what I'm being handed. Is there a more direct way to access these items? I tried adding an IBOutlet to the class that loads the nib, but these objects are meant to be generic building blocks and setting filesOwner to a specific class doesn't make any sense. I also tried making a copy method to load it once and just copy it as many times as I need but no luck.

Here's how I'm loading the nibs and getting the object I'm interested in. Anyone know of a more direct way to do this?



static	NSNib		*gPageRow			= nil;


@implementation PMXOpenProjectPageList

+ (void) initialize
{
@synchronized(self)
{
if (gPageRow == nil)
{
NSBundle *bundle = [NSBundle bundleForClass: [self class]];

gPageRow = [[NSNib alloc] initWithNibNamed: @"PMXPageListView" bundle: bundle];

NSLog(@"gPageRow: %@", gPageRow);
}
}
}



-(void) setModel:(NSMutableArray *) inModel
{
NSEnumerator *enumerator = [inModel objectEnumerator];

NSRect selfFrame = [self frame],
pageFrame,
pageNumFrame;

NSMutableDictionary *pageModel;
NSArray *topLevelObjects;

PMXPageListView *pageView;

float nextYOrigin = selfFrame.size.height;

[inModel retain];
[model release];

model = inModel;

while (pageModel = [enumerator nextObject])
{
[gPageRow instantiateNibWithOwner: self topLevelObjects: &topLevelObjects];
//NSLog(@"tempPageView: %@", tempPageView);
//NSLog(@"topLevelObjects: %@", topLevelObjects);
[topLevelObjects makeObjectsPerformSelector:@selector(release)];
pageView = [self getPageRow: topLevelObjects];

if (pageView != nil)
{
pageFrame = [pageView frame];
nextYOrigin -= pageFrame.size.height;
[pageView setFrame: NSMakeRect(0, nextYOrigin, selfFrame.size.width, pageFrame.size.height)];
[pageView setModel: pageModel];
[self addSubview: pageView];
}
}
}


// This seems like a really clunky way to get the only custom view contained in a nib...
- (id) getPageRow:(NSArray *) inArray
{
NSEnumerator *enumerator = [inArray objectEnumerator];
id obj;

while (obj = [enumerator nextObject])
{
if ([obj isKindOfClass: [PMXPageListView class]])
return obj;
}

return nil;
}
_______________________________________________


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


  • Follow-Ups:
    • Re: What's the best way to access top level objects loaded from a nib?
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: MobileMe API for uploading photos
  • Next by Date: Re: Type Declaration With Protocol
  • Previous by thread: Re: Adding multiple NSTextViews inside one NSScrollView
  • Next by thread: Re: What's the best way to access top level objects loaded from a nib?
  • Index(es):
    • Date
    • Thread