0
votes

Ok, this seems like it should very simple, but I'm coming from iOS and and I must be missing something very obvious. So I have a custom subclass of NSButtonCell. If I create a NSButton in IB and assign the NSButtonCell in IB, it works no problem.

However, I need to programmatically create this button. I've looked at a couple of examples and have the following within awakeFromNib, however, it creates what appears to be a regular button with my custom button cell underneath (I can tell when I click on the button).

NSButton* button = [[NSButton alloc] initWithFrame:NSMakeRect(100, 100, 60, 30)];
CT_CaptureButtonCell* captureCell = [[CT_CaptureButtonCell alloc] init];
[button setCell:captureCell];
[captureCell release];
[self.view addSubview:button];

So what dumb thing am I missing / not understanding? Thanks.

1
I haven't understood what you're trying to do.The button appears regularly and when you click on in you can see the button cell.What did you except to see instead?Ramy Al Zuhouri
For testing purposes, the custom button cell is red. I see a regular button, but when I press the regular button shifts slightly and I can see the red cell around the edges. I'm expecting to see the red button all the time (which is what I see when I hook things up in IB).InfalibleCoinage

1 Answers

0
votes

If you look at the documentation for "setCell:", it states:

Discussion

Use this method with great care as it can irrevocably damage the affected control; specifically, you should only use this method in initializers for subclasses of NSControl.

The way I read this is that you should be calling your "setCell" from within the init method for a subclass of "NSButton". In other words, write your own NSButton subclass (e.g. "ICButton", for InfalibleCoinage) and then stuff the "setCell" call into the init method there.

And while we're on the subject, what's the big picture of what you are exactly trying to accomplish with "CT_CaptureButtonCell" and can you do it without using a custom button cell?