noob q: adding a button to a window programmatically
noob q: adding a button to a window programmatically
- Subject: noob q: adding a button to a window programmatically
- From: Stuart Malin <email@hidden>
- Date: Mon, 9 Jun 2008 22:28:10 -0700
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.
_______________________________________________
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