将委托 -viewWillMoveToWindow 添加到包含表的视图子类。这里我使用了BOOL
名为reloadTable
. NSTrackingArea是您问题的答案
- (void) viewWillMoveToWindow:(NSWindow *)newWindow
{
// Setup a new tracking area when the view is added to the window.
NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[yourTable frame]
options: (NSTrackingMouseEnteredAndExited |
NSTrackingActiveAlways|NSTrackingEnabledDuringMouseDrag) owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
}
- (void) mouseEntered:(NSEvent*)theEvent {
reloadTable=YES;
NSLog(@"enter %@",theEvent);
}
- (void) mouseExited:(NSEvent*)theEvent {
reloadTable=YES;
}
然后在你的NSTableViewDataSource
方法中使用它