Skip navigation.
 
mlRe: Adding a new type of NSButton
FROM : Kevin Elliott
DATE : Wed Jun 25 22:13:44 2008

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?

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).

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.  You could also go after the responder chain- possibly in 
"mouseDown:".

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.

Related mailsAuthorDate
mlAdding a new type of NSButton P Teeson Jun 25, 21:12
mlRe: Adding a new type of NSButton Marco Masser Jun 25, 21:21
mlRe: Adding a new type of NSButton I. Savant Jun 25, 21:22
mlRe: Adding a new type of NSButton I. Savant Jun 25, 21:24
mlRe: Adding a new type of NSButton Kevin Elliott Jun 25, 22:13
mlRe: Adding a new type of NSButton I. Savant Jun 25, 22:26
mlRe: Adding a new type of NSButton Andy Lee Jun 25, 22:32
mlRe: Adding a new type of NSButton Andy Lee Jun 25, 23:10
mlRe: Adding a new type of NSButton P Teeson Jun 25, 23:44
mlRe: Adding a new type of NSButton P Teeson Jun 25, 23:54
mlRe: Adding a new type of NSButton P Teeson Jun 26, 00:01
mlRe: Adding a new type of NSButton Hamish Allan Jun 26, 00:37
mlRe: Adding a new type of NSButton P Teeson Jun 26, 01:16
mlRe: Adding a new type of NSButton I. Savant Jun 26, 15:29
mlRe: Adding a new type of NSButton I. Savant Jun 26, 15:33
mlRe: Adding a new type of NSButton Andy Lee Jun 26, 16:51
mlRe: Adding a new type of NSButton I. Savant Jun 26, 17:02
mlRe: Adding a new type of NSButton Kevin Elliott Jun 26, 18:13
mlRe: Adding a new type of NSButton I. Savant Jun 26, 18:33