【发布时间】:2014-10-21 03:17:42
【问题描述】:
我有一个 NSOutlineView,我在其中实现了拖放,它的值是通过绑定填充的。
一切都为我想要的逻辑工作,这基本上是只能在根级别项目之间放置的能力,并且不允许将子级拖放到任何地方。因此,如果您愿意,我只是尝试重新订购。
我的问题与我的 NSOutlineView 在视图中接受丢弃的位置有关。看来它只允许我放在行的最左侧。我似乎不能放弃其他任何地方。我的行是基于视图的,并且有一个图像视图。
这表明它工作正常
这是它不工作。
这是我的 acceptDrop 代码。
- (NSDragOperation)outlineView:(NSOutlineView *)ov validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)childIndex {
// Check to see what we are proposed to be dropping on
NSTreeNode *targetNode = item;
// A target of "nil" means we are on the main root tree
if (targetNode == nil) {
//If were dropping on the physical item lets say no
if (childIndex == NSOutlineViewDropOnItemIndex) {
return NSDragOperationNone;
}
//otherwise we are in-between so lets return move.
return NSDragOperationMove;
} else {
return NSDragOperationNone;
}
}
这可能与我的视图设置而不是我的 NSOutlineView 代码有关吗?
更新:
无论我的光标在哪里,它都适用于最上面一行,但对于所有其他行,它只适用于最左边。
【问题讨论】:
-
我刚刚遇到了同样的问题。如果您将鼠标悬停在左侧,则proposedChildIndex 是正确的。但如果将光标移到中间,则proposedChildIndex 为0 或-1。我现在头疼,你是怎么解决这个问题的?
-
@EdwardAnthony 我在下面回答了。
-
是的,但是使用下面的解决方案,我无法获得正确的 drop index (proposedChildIndex)。除非我将光标向左移动,否则它只返回 0 或 -1。我不知道这是否是一个错误。我尝试将 git reset 设置为昨天的提交,它显示了同样的问题。我清楚地记得这不是昨天发生的。
-
经过3个小时的挖掘,我发现这确实是AppKit的一个bug,你下面的解决方案是有效的。谢谢。
标签: macos cocoa drag-and-drop nsoutlineview