• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSButtonCell inside custom NSCell not responding to mouse events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSButtonCell inside custom NSCell not responding to mouse events


  • Subject: NSButtonCell inside custom NSCell not responding to mouse events
  • From: Oliver Quas <email@hidden>
  • Date: Mon, 4 Jun 2007 11:40:00 +0200

Hello,

i implemented a custom NSCell class named OQCell (see code below) for use as NSTableView's dataCell. For user interaction purposes, OQCell contains a NSButtonCell inside, which when clicked, should invoke @selector(closeButtonAction:) on OQCell. Right now, the NSButtonCell draws fine inside OQCell, but when clicking it, nothing happens.

I guess it has something to do with mouse tracking inside the NSButtonCell which never begins its job, right? How would i have to implement this, so the NSButtonCell would work correctly?

Sorry if this has been asked/answered before - but i couldn't find any solution to the problem, neither on the web, nor in the docs, and my own implementation doesn't work as expected. So any help is greatly appreciated.

Thanks in advance!
oliver


here's an excerpt from the code of my custom cell:



@interface OQCell : NSCell <NSCoding, NSCopying> {
    NSButtonCell *closeButtonCell;
}

- (void)closeButtonAction:(id)sender;

@end


@implementation OQCell

#pragma mark -
#pragma mark Init & Destroy

- (id)initTextCell:(NSString *)aString
{
    if (self = [super initTextCell:aString]) {
        closeButtonCell = [[NSButtonCell alloc] init];
        [closeButtonCell setButtonType:NSPushInCell];
        [closeButtonCell setTarget:self];
        [closeButtonCell setAction:@selector(closeButtonAction:)];
    }
    return self;
}

- (void)dealloc
{
    [closeButtonCell release];
    [super dealloc];
}

#pragma mark -
#pragma mark NSCoding

- (id)initWithCoder:(NSCoder *)decoder
{
    self = [super initWithCoder:decoder];
    [decoder decodeObjectForKey:@"closeButtonCell"];
	return self;
}

- (void)encodeWithCoder:(NSCoder *)coder
{
    [super encodeWithCoder:coder];
    [coder encodeObject:closeButtonCell forKey:@"closeButtonCell"];
}

#pragma mark -
#pragma mark NSCopying

- (id)copyWithZone:(NSZone *)zone
{
    OQCell *returnValue;
    returnValue = [super copyWithZone:zone];
    returnValue->closeButtonCell = [closeButtonCell copy];
    return returnValue;
}

#pragma mark -
#pragma mark Accessors

- (void)closeButtonAction:(id)sender
{
    // if the buttonCell is clicked, this method should be invoked
    NSLog(@"yay! :)");
}

#pragma mark -
#pragma mark NSCell Subclass

- (void)setControlView:(NSView *)view
{
    [super setControlView:view];

// keep our buttonCell updated as well, because it's inside the same controlView
[closeButtonCell setControlView:view];
}


#pragma mark -
#pragma mark Drawing

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *) controlView
{
// do some drawing...


    // now draw our buttonCell...
    [closeButtonCell drawWithFrame:someRect inView:controlView];
}

@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: NSButtonCell inside custom NSCell not responding to mouse events
      • From: Oliver Quas <email@hidden>
  • Prev by Date: Re: Question about NSArrayController
  • Next by Date: Re: Custom preview for NSOpenPanel
  • Previous by thread: [Moderator] List guidelines and related resources
  • Next by thread: Re: NSButtonCell inside custom NSCell not responding to mouse events
  • Index(es):
    • Date
    • Thread