我有一个包含NSTableView
的弹出式状态栏应用程序。当一行被拖到表外时(拖放完全在这里工作,这不是问题的焦点)我将光标更改为poofy-pointer,也称为[NSCursor disappearingItemCursor]
,如下所示:
- (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint {
if (self.draggedRowCanBeDeleted) {
BOOL outside = !NSPointInRect(screenPoint, window.frame);
if (outside) {
[[NSCursor disappearingItemCursor] set];
} else {
[[NSCursor arrowCursor] set];
}
}
}
这是非常不可靠的,因为它有时不起作用。它通常在第一次尝试时起作用,但在此之后退出工作。我似乎无法找到一个模式,我正在拖动,或拖动行程等...,只是它看起来很不稳定。我在这里做错了吗?如果没有,我可以做些什么来帮助诊断问题?
的更新
我还尝试了push
/ pop
路线,问题仍然存在。
- (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint {
if (self.draggedRowCanBeDeleted) {
BOOL outside = !NSPointInRect(screenPoint, window.frame);
if (outside) {
if (!_showingPoof) {
_showingPoof = YES;
[[NSCursor disappearingItemCursor] push];
}
} else {
if (_showingPoof) {
_showingPoof = NO;
[[NSCursor disappearingItemCursor] pop];
// I have also tried: [NSCursor pop];
}
}
}
}
的更新
我也尝试使用sourceOperationMaskForDraggingContext
方法进行设置。我可以确认正确的部分是在正确的时间被调用的,但是当走这条路线时光标永远不会改变。
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
if (self.draggedRowCanBeDeleted) {
switch(context) {
case NSDraggingContextOutsideApplication:
[[NSCursor disappearingItemCursor] set];
return NSDragOperationDelete;
break;
case NSDraggingContextWithinApplication:
[[NSCursor closedHandCursor] set];
return NSDragOperationMove;
default:
[[NSCursor arrowCursor] set];
return NSDragOperationNone;
}
}
return NSDragOperationNone;
}