Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7997439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:57:54+00:00 2026-06-04T14:57:54+00:00

I’ve subclassed the cells of a NSOutlineView, by setting the custom class in interface

  • 0

I’ve subclassed the cells of a NSOutlineView, by setting the custom class in interface builder.

I’ve implemented this delegate method to configure the cells:

- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item

Also, I’ve implemented this method in my custom cell class:

- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView 

which is invoked twice every time I click on the cell. I’m wondering why not just once. The event type is always MouseDown.

I don’t know if this matters, but it is invoked twice even if the cell has not parents or children. So it can’t be the cells hierarchy.

If I can’t rely on hitTestForEvent to trigger an action when a specific area of my cell is clicked, which method should I use ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:57:56+00:00Added an answer on June 4, 2026 at 2:57 pm

    -hitTestForEvent:inRect:ofView is entirely the wrong method to be using to trigger actions. You should be using -trackMouse:inRect:ofView:untilMouseUp:, or -startTrackingAt:inView:, -continueTracking:at:inView: and -stopTracking:at:inView:mouseIsUp:.

    Important Note: If you implement your own mouse tracking loop in -trackMouse:inRect:ofView:untilMouseUp:, you should document this fact somewhere, because generally speaking it will preclude the use of the other three methods. Some of the NSCell subclasses in the AppKit framework do this and fail to document that they have done so (with the result that you’ll ponder for hours why it is that -startTrackingAt:inView: never gets called).

    How do you implement your own tracking loop? Like this:

    - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame
                ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp
    {
      NSPoint pos = [controlView convertPoint:[theEvent locationInWindow]
                                     fromView:nil];
    
      if ([theEvent type] == NSLeftMouseDown && NSPointInRect (pos, myClickRect)) {
        NSWindow *window = [controlView window];
        NSEvent *myEvent;
        NSDate *endDate = [NSDate distantFuture];
    
        while ((myEvent = [window nextEventMatchingMask:(NSLeftMouseDragged
                                                         |NSLeftMouseUp)
                                              untilDate:endDate
                                                 inMode:NSEventTrackingRunLoopMode
                                                dequeue:YES])) {
          if ([myEvent type] != NSLeftMouseUp)
            continue;
    
          pos = [controlView convertPoint:[theEvent locationInWindow]
                                 fromView:nil];
    
          if (NSPointInRect (pos, myClickRect)) {
            // React somehow
          }
    
          return YES;
        }
      }
    
      return [super trackMouse:theEvent inRect:cellFrame ofView:controlView
                  untilMouseUp:untilMouseUp];
    }
    

    (The above code was just typed in here, so the usual caveats apply; it assumes the existence of an NSRect called myClickRect that defines the active area of your cell. You might need to calculate that from cellFrame at the head of the method.)

    Obviously you can watch for and handle other events too, if they are relevant to you.

    Perhaps I should also add that the three method approach, while conceptually cleaner, tends to be quite a bit slower, which generally leads me to prefer overriding -trackMouse:inRect:ofView:untilMouseUp: as shown above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.