• 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
Re: Using an IB-built view multiple times
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using an IB-built view multiple times


  • Subject: Re: Using an IB-built view multiple times
  • From: James Housley <email@hidden>
  • Date: Tue, 20 Sep 2005 20:35:46 -0400

On Sep 20, 2005, at 7:41 PM, Christopher Drum wrote:

No, I'm sorry if my original explanation was confusing. I mean, I want to build a view in IB, then use that view repeatedly to populate some master view programatically. I have found an example of this in some sample Apple code in the CoreRecipes application. There is an option for adding and subtracting search predicates, each of which is an instance of an IB-built view. These instances are then added as subviews to a primary view. I had not seen that code prior to my question.

I'm still struggling with it a little. As I understand the CoreRecipes code, ClassA can contain a non-instantiated member variable pointing to an NSView. ClassB can instantiate a view from an NSNib citing an object of ClassA as the owner. Somehow, through a magical mechanism I fail to see, ClassA's NSView and ClassB's instantiation then link up properly during initWithNibNamed:bundle:, after which the NSView can be accessed via ClassA's member variable for that view.

I'm working on some sample code to verify this process, but thanks everyone for pointing me toward the NSNib. All that research into NSBundle and I just never came across NSNib. The initial struggle was understanding how to suck the NSView out of the NSNib for adding as a subview to my primary view. That process still seems a little cryptic to me, but I think I'm making progress.

Any insight into understanding this process would be appreciated. Apple's docs seem to stop a little short of explaining how the member variables of the owner and the objects of the NIB sort themselves out. What if I had three pulldown menus in my secondary NIB that needed to be instantiated and linked up to the owner object? How would I tell the owner object which NIB menu links up to which member variable of the owner? Is that where instantiateNibWithExternalNameTable: comes into play? I'm finding the Apple docs a little confusing about the order of events and I don't really see many samples of putting these methods to use.

Christopher Drum


On Sep 20, 2005, at 4:03 PM, Ricky Sharp wrote:


When you say "build the template graphically", do you mean dragging out instances of them in IB?


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


I am doing something similar, I think. Here are some code segments.


NSNib *rawNib = [[NSNib alloc] initWithNibNamed:@"raw.nib" bundle:[NSBundle mainBundle]];


newTab = [[NSTabViewItem alloc] initWithIdentifier:[self extensionName]];
newView = [[NSView alloc] initWithFrame:containerSize];
[newTab setView:newView];
[newView release];
[newTab setLabel:[self displayName]];
[destView addTabViewItem:newTab];
[newTab release];


[topLevelObjects release];
topLevelObjects = [[NSMutableArray alloc] init];
[rawNib instantiateNibWithOwner:nil topLevelObjects:&topLevelObjects];


destContentView = [Logic moveObjectsFrom:[(NSTabView *) [[[(NSWindow *)[topLevelObjects objectAtIndex:0] contentView] subviews] objectAtIndex:0] tabViewItemAtIndex:0] to:[destView tabViewItemAtIndex:index]];

    [rawXMLNib release];

/////////////////////////////

+ (NSClipView *)moveObjectsFrom:(NSTabViewItem *)source to: (NSTabViewItem *)destination
{
int maxY;
NSRect aRect;
NSEnumerator *enumerator;
id object;
NSScrollView *newScrollView;


[[destination view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[destination view] setAutoresizesSubviews:YES];


maxY = 0;
aRect.origin.x = 0;
aRect.origin.y = 0;
aRect.size = [[destination view] frame].size;
newScrollView = [[NSScrollView alloc] initWithFrame:aRect];
[newScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[newScrollView setAutoresizesSubviews:YES];
[newScrollView setHasHorizontalScroller:NO];
[newScrollView setHasVerticalScroller:YES];
[newScrollView setAutohidesScrollers:YES];
[newScrollView setDrawsBackground:NO];
[newScrollView setBorderType:NSNoBorder];
[[newScrollView verticalScroller] setControlSize:NSSmallControlSize];


    aRect = [[newScrollView contentView] frame];
    flippedView *docView = [[flippedView alloc] initWithFrame:aRect];
    [docView setAutoresizesSubviews:YES];
    [docView setAutoresizingMask:NSViewWidthSizable];

[newScrollView setDocumentView:docView];
[[newScrollView contentView] setAutoresizesSubviews:YES];
[[newScrollView contentView] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];


    [[destination view] addSubview:newScrollView];
    [newScrollView release];

    enumerator = [[[source view] subviews] objectEnumerator];
    while (object = [enumerator nextObject])
    {
        [object retain];
        [object removeFromSuperviewWithoutNeedingDisplay];
        [[newScrollView contentView] addSubview:object];
        aRect = [object frame];
        if (aRect.origin.y+aRect.size.height > maxY)
        {
            maxY = aRect.origin.y+aRect.size.height;
        }
    }

    // size to just contain the contents
    if (maxY > 0)
    {
        aRect = [docView frame];
        aRect.size.height = maxY + 18;
        [docView setFrameSize:aRect.size];
    }

    return [newScrollView contentView];
}

I hope that maybe this will help
--

/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
 X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
email@hidden      http://www.FreeBSD.org     The Power to Serve
email@hidden  http://www.TheHousleys.net
---------------------------------------------------------------------
Do not meddle in the affairs of dragons, for you are crunchy and taste
    good with ketchup.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Using an IB-built view multiple times (From: Christopher Drum <email@hidden>)
 >Re: Using an IB-built view multiple times (From: Ricky Sharp <email@hidden>)
 >Re: Using an IB-built view multiple times (From: Christopher Drum <email@hidden>)

  • Prev by Date: Re: Using an IB-built view multiple times
  • Next by Date: NSView subclass bindings code?
  • Previous by thread: Re: Using an IB-built view multiple times
  • Next by thread: Re: Using an IB-built view multiple times
  • Index(es):
    • Date
    • Thread