无法拖放NSOutlineView的整行

时间:2014-10-21 03:17:43

标签: macos cocoa drag-and-drop nsoutlineview

我有一个NSOutlineView,其中我实现了拖放,它的值通过绑定填充。

一切都在为我想要的逻辑工作,这基本上只能在根级别项之间删除,并且不允许在任何地方拖放或删除子项。所以我只是想尝试实施重新订购。

我的问题在我的NSOutlineView接受丢弃的视图上发挥作用。它似乎只允许我放在行的最左侧。我似乎无法放弃其他任何地方。我的行是基于视图的,并有一个图像视图。

This one is working这表明它正常工作

Here is it not working.这不起作用。

继承我的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代码吗?

更新

无论我的光标在哪里,它都可以在最上面的行上工作,但只能在最左边的所有其他行上工作。

1 个答案:

答案 0 :(得分:0)

这解决了它。

NSUInteger maxNumberOfRows = [[_hostController arrangedObjects] count];
// 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) {
        [ov setDropItem:nil dropChildIndex:maxNumberOfRows];
        return NSDragOperationMove;
    }
    [ov setDropItem:nil dropChildIndex:childIndex];
    return NSDragOperationMove;
} else {
    //If its not a host we dont want to allow drop
    if (![self isHost:[item representedObject]]) {
        return NSDragOperationNone;
    }
    if (childIndex == NSOutlineViewDropOnItemIndex) {
        [ov setDropItem:nil dropChildIndex: [ov rowForItem:item]];
        return NSDragOperationMove;
    }
    return NSDragOperationNone;
}