使用拖放进行重新排列时,NSOutlineView顶部的小圆圈线棒被卡住 [英] Little circle-line bar stuck at top of NSOutlineView when rearranging using drag and drop

查看:163
本文介绍了使用拖放进行重新排列时,NSOutlineView顶部的小圆圈线棒被卡住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有NSOutlineView,它仅列出根项的子项.一切正常,除了当我尝试使用拖放功能重新排列项目时降低.前面带有圆圈的线始终位于第一行的上方,并且在需要在其他项目之间拖动时不会跟随我的项目.但是,我仍然可以正确地获得索引位置,因此仍可以在数据源中正确地重新排列它们.我不想通过将它们拖到彼此上来重新排列项目,我只想从根级别开始重新排列项目(如Mac上的VLC播放列表).

I've got NSOutlineView that, at the moment, only lists children of the root item. Everything works except when I try to rearrange items using drag & drop. The line with the circle in front of it always stays above the top row and doesn't follow my items when they need to be dragged between other items. However, I still get the index positions properly so I can still rearrange them in the datasource properly. I don't want to rearrange items by dragging them onto each other, I only want to rearrange the items off the root level (like the VLC playlist on the Mac).

这是我的四个必需方法:

Here are my four required methods:

//queue is a C-based data structure

-(NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
    if(item == nil){
        return queue.count; //each list item
    }else{
        return 0; //no children of each list item allowed
    }
}

-(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
    if(item != nil) return nil;

    return [[NSDictionary dictionaryWithObjectsAndKeys:
             [NSNumber numberWithLong:index],@"index",
             [NSString stringWithFormat:@"%s",queue.item[index].filepath],@"filePath",
             nil] copy];
}

-(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
    if(item == nil){
        return YES;
    }else{
        return NO;
    }
}

-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
    if(item == nil) return nil;

    return [item objectForKey:[tableColumn identifier]];
}

还有我的拖动方法:

-(BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard
{
    [pasteboard declareTypes:[NSArray arrayWithObject:LOCAL_REORDER_PASTEBOARD_TYPE] owner:self];
    [pasteboard setData:[NSData data] forType:LOCAL_REORDER_PASTEBOARD_TYPE];
    return YES;
}

-(NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
{
    NSUInteger op = NSDragOperationNone;

    if(index != NSOutlineViewDropOnItemIndex){
        op = NSDragOperationMove;
    }
    return op;
}

推荐答案

对于所需的行为,我有些困惑.此示例项目是否实现了所需的拖放突出显示行为(它在每行之间显示了o––––––指示器,这对于我来说VLC似乎是这样工作的):

I'm kind of confused about what desired behavior you want. Does this sample project achieve the desired drag and drop highlighting behavior (it shows the o–––––– indicator between each row, which is how VLC appears to work here for me):

http://www.markdouma.com/developer/NSOutlineViewFinagler.zip

(请注意,该代码尚不包含实际对项目进行重新排序的代码).

(Note that it doesn't include code yet to actually carry through the reordering of the items).

如果没有,您能否再次描述它目前正在做什么以及您希望它做什么?

If not, can you describe again what it currently does now and what you want it to do?

此外,您没有在此处包含代码,但是您确定要注册LOCAL_REORDER_PASTEBOARD_TYPE拖动类型的轮廓视图吗?我会在awakeFromNib中完成该操作:

Also, you didn't include code for it here, but did you make sure to register the outline view for the LOCAL_REORDER_PASTEBOARD_TYPE drag type? I would do it in awakeFromNib:

- (void)awakeFromNib {
    [self.outlineView registerForDraggedTypes:@[LOCAL_REORDER_PASTEBOARD_TYPE]];
}

对于轮廓视图来说,使其成为拖动目标是必要的.

That's necessary for the outline view to allow itself to be a drag destination.

这篇关于使用拖放进行重新排列时,NSOutlineView顶部的小圆圈线棒被卡住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆