从 NSOutlineView 拖动从未被接受
我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,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.