Re: building a custom NSView with IB?
Re: building a custom NSView with IB?
- Subject: Re: building a custom NSView with IB?
- From: Corbin Dunn <email@hidden>
- Date: Mon, 08 Dec 2008 16:57:33 -0800
Le Dec 8, 2008 à 3:58 PM, Bill Janssen a écrit :
Corbin Dunn <email@hidden> wrote:
I'd like to build a custom view that is just an assemblage of an
NSTextView, a couple of pushbuttons, and a checkbox. It seems to me
that there should be some way to do this with IB, but I haven't
figured
it out yet. All the examples on the net seem to focus on overriding
drawRect, which I *don't* need to do. Anyone have an example of
doing
this?
It should be as easy as dragging a custom NSView out into your nib,
and placing your subviews on it.
That was my thinking, too. Perhaps I'm just doing the wrong thing
with it.
I've got a few outlets and actions defined in the Custom view that are
connected to the buttons and textview. Something has to run to hook
them together, after instantiating an instance of the custom view.
Seems
to me the standard way of doing this is to somehow just save the
custom view
to a separate nib, and reinstantiate it from that nib. Is that
correct?
No; you don't instantiate the view; you load it from the nib. I think
that is where you are going wrong. Something like this:
+ (NSView *)yourView {
NSNib *nib = [[NSNib alloc] initWithNibNamed:@"YourNibName"
bundle:...your bundle];
NSArray *objects = nil;
[nib instantiateNibWithOwner:nil topLevelObjects:&objects];
for (id object in nib) {
if ([object isKindOfClass:[NSView class])) {
// you found the view, provided you have only one top
level view
}
}
[nib release];
return [view autorelease];
}
A better way would be to create an "owner" that is passed, and have
the owner have an outlet hooked up to the view.
corbin_______________________________________________
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