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

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to