Re: Adding a new type of NSButton
Re: Adding a new type of NSButton
- Subject: Re: Adding a new type of NSButton
- From: P Teeson <email@hidden>
- Date: Wed, 25 Jun 2008 18:01:28 -0400
On 25-Jun-08, at 4:13 PM, Kevin Elliott wrote:
On Jun 25, 2008, at 12:12 PM, P Teeson wrote:
Environment is Mac OS X 10.4.11 Xcode 2.5
I need a new type of NSButton/NSButtonCell that I am calling an
NSLatchButton.
Once it is pushed it stays pushed - pushing it again does not
revert it back to unpushed state.
(Of course there would be a method to set it to it's unlatched
state but pushing the button would not
invoke that action)
However I'm not sure how to approach this. Should I use
categories, extensions, or subclass or what?
Is this something are going to use in one place only, or is this
something you foresee using in a lot of different places?
There are at least two apps where I can use this concept of a Latch.
What appealed to me about the NSButton was it maturity as an
interface item and I wanted to take advantage of that.
I thought making another variant of it was cleaner.
If this is something that's a one off control, I'd probably put the
logic in the IBAction rather than subclassing.
If you need to use this a lot of different places/projects then
it's probably worth subclassing.
I don't think you can accomplish your goal using categories (wrong
tool).
OK Thanks....
In terms of what you need to override that would take some
experimentation and thinking.
Couple options come to mind- you might try overriding "setState:"
and eating any state changes after the first.
That was the one that occurred to me.
You could also go after the responder chain- possibly in "mouseDown:".
That can get a bit messy and I think goes beyond my needs.
Other peoples comments about this being a "Controller" problem and
not something that belongs in the
Model are somewhat true, but if this is really a button type your
going to use in several places then subclassing
is perfectly appropriate. Also, if it's important to you that the
user not get any click behavior
(that is, once the button has been "set" then clicking on it again
has no visible effect on the control),
then I don't think you'll be able to get what you want without
subclassing.
Yes at present I have code in the Controller. But because I can see
uses for it in other apps I plan I raised the
idea of adding it as a type by sub-classing.
Thanks for your input Kevin.
respect....
Peter
_______________________________________________
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