Re: Build objects at runtime
Re: Build objects at runtime
- Subject: Re: Build objects at runtime
- From: Clark Cox <email@hidden>
- Date: Mon, 26 Jul 2004 15:34:28 -0400
On 7 26, 2004, at 14:42, Peter Karlsson wrote:
>
Dear list!
>
>
Attached to my main window is a drawer.
>
>
When the user press a button I want to programatically build a tabview
>
with 1 - 20 tabs depending on what the user decides to do.
>
>
Under the different tabs I want to build buttons, sliders and so on,
>
also depending on what the user decides to do.
>
>
I want the tabview to show up in the drawer next time the user opens
>
the drawer. And I want the tabview to be saved so the next time the
>
user opens the app everything is still there.
>
>
I can't do this in IB because it's the user that decides at runtime
>
how many tabs, buttons, sliders and so on that is gonna be used. I
>
suppose I must programatically build a nib file at runtime, but how?
>
>
Can someone please give me some guidelines how to do all this so I can
>
continue search on the internet for more information?
There really isn't anything magical that IB does. You can create your
own views in code, just like you would any other object (i.e. by using
[[Class alloc] init...]). For example, say you wanted to create a
button, and add it to a view, you could do the following:
{
//This could be an outlet from IB, or a view that you created manually
NSView *theSuperview = ...;
NSRect myButtonFrame = ...;
NSButton *myButton = [[NSButton alloc] initWithFrame:
myButtonFrame];
//The following two lines are like ctrl-dragging
//from the button to it's target in IB, and selecting an action
[myButton setTarget: someTarget];
[myButton setAction: @selector(someAction:)];
//This call actually adds the button to the superview
[theSuperView addSubView: myButton];
//Release our reference to the button:
[myButton release];
}
This same basic pattern can be followed for just about any view or
control
For more information, you may want to read:
<
http://developer.apple.com/documentation/Cocoa/Conceptual/DrawViews/
index.html#//apple_ref/doc/uid/10000079i>
--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.