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: Graham Cox <email@hidden>
- Date: Tue, 10 Jun 2008 16:04:39 +1000
You haven't set the button's frame size. If you use -initWithFrame:
and pass something sensible that should work. Note - because NSButton
subclasses NSView, the designated initializer for NSView
(initWithFrame;) must be used.
hth,
Graham
On 10 Jun 2008, at 3:28 pm, 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.
_______________________________________________
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
_______________________________________________
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