Re: noob q: adding a button to a window programmatically
Re: noob q: adding a button to a window programmatically
- Subject: Re: noob q: adding a button to a window programmatically
- From: Bob Warwick <email@hidden>
- Date: Tue, 10 Jun 2008 02:56:32 -0300
On 10-Jun-08, at 2:28 AM, Stuart Malin wrote:
Until now I have created my GUIs using IB. I want a better
understanding of what goes on "under the hood" of instantiating a
Nib, so decided to try adding a button to a window programmatically.
I can't get the button to appear, and so presume I am missing some
fundamental concept. Here's my code:
NSButton *button = [[NSButton alloc] init];
[button setTitle:@"New Button"];
[button setHidden:NO];
[button setButtonType:NSPushOnPushOffButton];
NSPoint p = NSMakePoint(0, 0);
[button setFrameOrigin:p];
NSView *theWindowContentView = [theWindow contentView];
[theWindowContentView addSubview:button];
[theWindowContentView setNeedsDisplay:YES];
[button release];
"theWindow" is an ivar that is set by Nib loading to hold a
reference to the window (my controller object is instantiated in the
Nib). Again, I know I must be overlooking something fundamental, so
would appreciate some guidance on the mechanics of instantiating
controls programmatically. TIA.
Use initWithFrame: instead of init. The button is a view subclass.
-Bob Warwick
_______________________________________________
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