<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCell/trackMouse(with:in:of:untilMouseUp:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCell(im)trackMouse:inRect:ofView:untilMouseUp:"
  },
  "title" : "trackMouse(with:in:of:untilMouseUp:)"
}
-->

# trackMouse(with:in:of:untilMouseUp:)

Initiates the mouse tracking behavior in a cell.

```
func trackMouse(with event: NSEvent, in cellFrame: NSRect, of controlView: NSView, untilMouseUp flag: Bool) -> Bool
```

## Parameters

`event`

The event that caused the mouse tracking to occur.

`cellFrame`

The receiver’s frame rectangle.

`controlView`

The view containing the receiver. This is usually an `NSControl` object.

`flag`

If <doc://com.apple.documentation/documentation/Swift/true>, mouse tracking continues until the user releases the mouse button. If <doc://com.apple.documentation/documentation/Swift/false>, tracking continues until the cursor leaves the tracking rectangle, specified by the `cellFrame` parameter, regardless of the mouse button state. See the discussion for more information.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the mouse tracking conditions are met, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

This method is generally not overridden because the default implementation invokes other `NSCell` methods that can be overridden to handle specific events in a dragging session. This method’s return value depends on the `untilMouseUp` flag. If `untilMouseUp` is set to <doc://com.apple.documentation/documentation/Swift/true>, this method returns <doc://com.apple.documentation/documentation/Swift/true> if the mouse button goes up while the cursor is anywhere; <doc://com.apple.documentation/documentation/Swift/false>, otherwise. If `untilMouseUp` is set to <doc://com.apple.documentation/documentation/Swift/false>, this method returns <doc://com.apple.documentation/documentation/Swift/true> if the mouse button goes up while the cursor is within `cellFrame`; <doc://com.apple.documentation/documentation/Swift/false>, otherwise.

This method first invokes [`startTracking(at:in:)`](/documentation/AppKit/NSCell/startTracking(at:in:)). If that method returns <doc://com.apple.documentation/documentation/Swift/true>, then as mouse-dragged events are intercepted, [`continueTracking(last:current:in:)`](/documentation/AppKit/NSCell/continueTracking(last:current:in:)) is invoked until either the method returns <doc://com.apple.documentation/documentation/Swift/false> or the mouse is released. Finally, [`stopTracking(last:current:in:mouseIsUp:)`](/documentation/AppKit/NSCell/stopTracking(last:current:in:mouseIsUp:)) is invoked if the mouse is released. If `untilMouseUp` is <doc://com.apple.documentation/documentation/Swift/true>, it’s invoked when the mouse button goes up while the cursor is anywhere. If `untilMouseUp` is <doc://com.apple.documentation/documentation/Swift/false>, it’s invoked when the mouse button goes up while the cursor is within `cellFrame`. You usually override one or more of these methods to respond to specific mouse events.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)