Re: How to create a button dynamically and set action in subclass
Re: How to create a button dynamically and set action in subclass
- Subject: Re: How to create a button dynamically and set action in subclass
- From: John Fox <email@hidden>
- Date: Mon, 6 Dec 2004 08:36:18 -0800
Hi Anish:
I've done something similar, by using a "prototype" view that I instantiate from a nib file and which is then positioned on screen over an NSImageView subclass. It's not terribly difficult to do, and since I've gotten lots of help from people on the list at various times, I'd be happy to help you with it.
Essentially, in IB you want to create your view object with whatever UI elements you need (a scrolling text field and/or a button, etc.). In that nib file: I suggest you create your own subclass to be the File's Owner. This will make it possible to take care of loading the nib file, take care of whatever configuration you need, etc. The File's Owner will also contain the action methods you need for when a button is clicked, etc.
To load the nib file, you use something like this in your class' init method:
[NSBundle loadNibNamed: @"MyNiftyNibFile" owner: self];
You'll want to make add this view to your NSImageView subclass by doing something like:
if (![[myImageView subviews] containsObject:mySubview])
{
[myImageView addSubview:mySubview];
}
You will also need to set the location, and possibly adjust the size of this view using NSView's
setFrameOrigin: and setFrameSize: methods.
Doubtless, there may be other approaches to solve this problem, but this technique has worked well for me.
Anyway, I hope this helps, and If not, feel free to get in touch, and I'll see if I can help you some more.
Take care,
John
_______________________________________________
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