NSTableView拖放不工作

NSTableView拖放不工作

本文介绍了NSTableView拖放不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的NSTableView设置非常基本的拖放。表视图具有单个列(带有自定义单元格)。该列绑定到一个NSArrayController,并且数组控制器的内容数组绑定到我的控制器对象上的NSArray。数据在表中显示正常。我将表视图的 dataSource 代理连接到我的控制器对象,然后实现这些方法:

I'm trying to set up very basic drag and drop for my NSTableView. The table view has a single column (with a custom cell). The column is bound to an NSArrayController, and the array controller's content array is bound to an NSArray on my controller object. The data displays fine in the table. I connected the dataSource and delegate outlets of the table view to my controller object, and then implemented these methods:

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
    NSLog(@"dragging");
    return YES;
}

- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)op
{
    return NSDragOperationEvery;
}

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
              row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
{
    return YES;
}



我还在 -awakeFromNib

#define MyDragType @"MyDragType"

- (void)awakeFromNib
{
    [super awakeFromNib];
    [_myTable registerForDraggedTypes:[NSArray arrayWithObjects:MyDragType, nil]];
}

问题是-tableView:writeRowsWithIndexes:toPasteboard: >从不调用。我看了一堆例子,我不知道我做错了什么。问题是我使用自定义单元格?有没有什么事情我应该重写在单元格子类中启用此功能?

The problem is that the -tableView:writeRowsWithIndexes:toPasteboard: method is never called. I've looked at a bunch of examples and I can't figure out anything I'm doing wrong. Could the problem be that I'm using a custom cell? Is there something I'm supposed to override in the cell subclass to enable this functionality?

编辑:已确认。切换常规NSTextFieldCell的自定义单元进行拖动工作。

Confirmed. Switching the custom cell for a regular NSTextFieldCell made dragging work. Now, how do I make drag and drop work with my custom cell?

推荐答案

我修复了自定义单元格

这篇关于NSTableView拖放不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:22