Re: Custom NSCell mouse events
Re: Custom NSCell mouse events
- Subject: Re: Custom NSCell mouse events
- From: Michael Hanna <email@hidden>
- Date: Tue, 15 Jun 2010 09:06:43 -0400
Thanks for the suggestion Corbin. It looks like I'm doing everything
OK with creation and destruction though. Here is my code:
- (id)init {
if ((self = [super init])) {
_checkboxCell = [[NSButtonCell alloc] init];
[_checkboxCell setButtonType:NSSwitchButton];
[_checkboxCell setTitle:@""];
[_checkboxCell setTarget:self];
[_checkboxCell setImagePosition:NSImageLeft];
[_checkboxCell setControlSize:NSRegularControlSize];
}
return self;
}
- copyWithZone:(NSZone *)zone {
MyCheckboxCellToo *cell = (MyCheckboxCellToo *)[super copyWithZone:zone];
cell->_checkboxCell = [_checkboxCell copyWithZone:zone];
return cell;
}
- (void)dealloc {
[_checkboxCell release];
[super dealloc];
}
On Mon, Jun 14, 2010 at 11:42 AM, Corbin Dunn <email@hidden> wrote:
>
> On Jun 10, 2010, at 9:43 AM, Michael Hanna wrote:
>
>> OK I'm really stumped on this one. I want to make a checkbox with a
>> NSTextFieldCell combined together. It's important that the checkbox
>> goes ON if the mouse hits the box, NOT the text. I've accomplished
>> this, more or less, but the issue is receiving the mouse event because
>> I click one checkbox in a row, but ALL of them turn to NSOnState. I
>> will show what I've done and my various failed attempts in order to
>> get this to work.
>>
>> So this is how I've done it so far:
>>
>> header:
>> @interface MyCheckboxCellToo : NSTextFieldCell {
>> NSButtonCell *_checkboxCell;
>> }
>
>>
>> implementation:
>
> <snip>
>
> You're missing an implementation of copyWithZone that copies the _checkboxCell ivar.
>
> Hence, all use the same instance and show the same stuff. You'll also eventually get a crash because the default implementation of copyWithZone is just a bitwise copy of the class.
>
> corbin
>
>
_______________________________________________
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