Re: Custom Views
Re: Custom Views
- Subject: Re: Custom Views
- From: Wain <email@hidden>
- Date: Tue, 11 Apr 2006 21:58:58 +0100
Hi,
Do you have a nib file with your view and text views in it?
You need to load the nib file and get your view from it, the view is
archived in the nib file, that's where the outlets are set.
It sounds like what you want to do is instantiate an NSView in IB and
add a few text views to your NSView.
Your nib file will have an owner, set the owner to whatever type of
class you choose, you want to add the outlets to the files owner.
Connect the outlets to the text views.
Now, in your code you need to init (initWithNibNamed:bundle:) and
then instantiate (instantiateNibWithOwner:topLevelObjects:) the nib
file with an instance of the class you chose as the nib owner.
if instantiateNibWithOwner:topLevelObjects: returns YES then your
owner should have all of it's outlets set.
Once you have this concept you can tailor your nib owner and content
to fit your needs.
Hope this all makes sense :-)
Wain
On 11 Apr 2006, at 21:19, Matt Mashyna wrote:
I've been looking for a way to create a custom container view so I
can instantiate as many as I need and add them as subviews in a
window. I thought I could make a subclass of NSView with a few text
views in it, instantiate it in a nib, connect the outlets and have
it ready to use. Of course, this doesn't work.
I was able to make the views and drop them with the code below but
the subviews are not connected to the outlets and they don't draw.
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the
windowController has loaded the document's window.
NSWindowController* myController = [[self windowControllers]
objectAtIndex:0];
NSWindow* myWindow = [myController window];
NSView* mainView = [myWindow contentView];
NSRect initPos = {{0.0, 0.0}, {200.0, 100.0}};
planBoxView* newView = [[planBoxView alloc] initWithFrame: initPos];
[mainView addSubview: newView];
[newView setNeedsDisplay: YES];
}
I can see in the debugger that the view I make this way is added
but its outlets are nils.
I want to make views for a project planner like MS Project. I want
one view with a few subviews connected to outlets. I was hoping
that I could make a view in IB and use it to drop them into my
window on the fly. Is there way to do it this way with IB or do I
need to lay my custom view out programatically ?
Is there a tech note for this ? I just can't find any Apple example
code that covers this kind of thing.
_______________________________________________
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: | |
| >Custom Views (From: Matt Mashyna <email@hidden>) |