从 NSOutlineView 拖动从未被接受

发布于 2024-12-07 15:55:16 字数 625 浏览 0 评论 0原文

我正在尝试从 NSOutlineView 实现拖动,尽管拖动开始正常,但它永远不会被另一个应用程序接受。相关代码是:

- (BOOL) outlineView:(NSOutlineView*)pOutlineView writeItems:(NSArray*)pItems toPasteboard:(NSPasteboard*)pBoard
{
    CItem* theItem = [pItems objectAtIndex:0];
    BOOL canDrag = ([theItem subItems] == 0);
    if (canDrag) {
        [pBoard clearContents];
        [pBoard writeObjects:[NSArray arrayWithObject:[theItem name]]];
    }

    return canDrag;
}

[theItem name] 返回一个 NSString*。在某些时候,我想向粘贴板内容添加更多内容,但在我可以让它使用简单的字符串之前,似乎没有太多意义。

拖动看起来不错,但将鼠标悬停在接收器上时不会显示任何突出显示,并且释放时拖动图像会“飞回”。

任何帮助感激不尽!

安迪牧师

I'm trying to implement dragging from an NSOutlineView and although the drag starts OK it is never accepted by another app. The pertinent code is:

- (BOOL) outlineView:(NSOutlineView*)pOutlineView writeItems:(NSArray*)pItems toPasteboard:(NSPasteboard*)pBoard
{
    CItem* theItem = [pItems objectAtIndex:0];
    BOOL canDrag = ([theItem subItems] == 0);
    if (canDrag) {
        [pBoard clearContents];
        [pBoard writeObjects:[NSArray arrayWithObject:[theItem name]]];
    }

    return canDrag;
}

[theItem name] returns an NSString*. At some point I'll want to add more to the pasteboard contents but until I can get it to work with a simple string there doesn't seem to be much point in getting into that.

The drag looks fine but the receiver doesn't show any highlighting when being hovered over and the drag image 'flies back' when released.

Any help gratefully received!

Rev. Andy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2024-12-14 15:55:16

事实证明,draggingSourceOperationMaskForLocal: 永远不会为 NSOutlineView(或可能是 NSTableView)的委托调用,因此永远不允许拖动操作。子类化 NSOutlineView 只是为了覆盖此方法可以解决所有问题。

Turns out that draggingSourceOperationMaskForLocal: is never called for the delegate of NSOutlineView (or NSTableView possibly) so that drag operation is never allowed. Subclassing NSOutlineView just to override this method fixes everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文