Re: Adding a new type of NSButton
Re: Adding a new type of NSButton
- Subject: Re: Adding a new type of NSButton
- From: "I. Savant" <email@hidden>
- Date: Wed, 25 Jun 2008 15:22:11 -0400
> 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?
Why do you need a new button type? No matter how you want it to
look, the behavior should be dictated by the controller layer. When
its action is fired, simply force its state to be NSOnState. Depending
on how you want it to appear, the existing NSButton/Cell should be
configurable to taste. If you want a custom appearance, just use
custom images (still, the standard button will work fine).
> If I were dealing with the source code I would add to the button types enums
> and add a method or case to deal with that type.
Yes, and I would snarf the freezlehopper until it is within one
tenth of a hoptzit of the specified framulator. But that's also
unnecessary. ;-) Yes, of course you can subclass NSButton/Cell and add
a new type, then override all the drawing routines, etc. to handle
that case, but you *still* shouldn't force the button to take on the
responsibility of application-specific logic (see "MVC design
pattern"). It's your application's idea that a button can't be
"unpushed" once it's pushed; it's your application's responsibility to
enforce such a state once set.
> But what suggestions do you have?
Read the NSButton documentation *and* the target/action mechanism
documentation (both easily searchable in Apple's reference library).
You're making a mountain out of a mole hill.
--
I.S.
_______________________________________________
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