Skip navigation.
 
mlRe: Adding a new type of NSButton
FROM : Andy Lee
DATE : Wed Jun 25 22:32:05 2008

On Jun 25, 2008, at 3:12 PM, P Teeson wrote:
> I need a new type of NSButton/NSButtonCell that I am calling an 
> NSLatchButton.


You shouldn't use the NS prefix -- someone reading your code might 
think it was a Cocoa class.  PTLatchButton would be fine.

> Once it is pushed it stays pushed - pushing it again does not revert 
> it back to unpushed state.


Are you able to say what this button would be used for?  I'm trying to 
think of an example where I'd use such a control.

On Jun 25, 2008, at 4:13 PM, Kevin Elliott wrote:
> 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.


This makes sense to me.  What you don't want to try to do is create a 
new button type enum (not that you could anyway).  Instead, work with 
and around existing behavior.

> 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's what I would try if I were to take the subclassing approach.  I 
can't say for sure it would work, but as a first pass I'd try 
something like this:


- (void)setState:(NSInteger)value
{
    if (value == NSOnState) {
        [super setState:value];
        [self setEnabled:NO];
    }
}


I would add another method called forceState:, like this:


- (void)forceState:(NSInteger)value
{
    [super setState:value];
}


Other objects in your program could call this method, with or without 
an accompanying call to [self setEnabled:YES].

--Andy

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