【问题标题】:writeRowsWithIndexes is not calling in NSTableView with custom cellwriteRowsWithIndexes 没有在带有自定义单元格的 NSTableView 中调用
【发布时间】:2014-09-09 12:27:05
【问题描述】:

我已经实现了以下委托以支持在 NSTableView 中拖放。调用了委托 validateDrop 和 acceptDrop,我可以将内容从 Finder 拖放到 NSTableView,但是当我尝试将项目从 NSTableView 拖放到 Finder 时,不会调用 writeRowsWithIndexes。

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

- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
{
 NSLog(@"validateDrop");
 return NSDragOperationCopy;
}

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

我已将拖动类型注册为

//Registering dragged Types
[tableView registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
//To support across application passing NO
[tableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
//Don't want any highlight selection on drop
[tableView setDraggingDestinationFeedbackStyle:NSTableViewDraggingDestinationFeedbackStyleNone];

在我的 NSTableView 中没有启动拖动,谁能告诉我可能的原因是什么?我在 TableView 中有自定义单元格,并且还正确设置了委托和数据源。

【问题讨论】:

  • 1.在命中和试验中,我发现拖动只是从单元格分隔符开始,而不是在单元格内容区域。 2.拖拽图片delegate也不叫——(NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent *)dragEvent offset:(NSPointPointer)dragImageOffset

标签: objective-c macos cocoa nstableview


【解决方案1】:

我找到了原因,这是由于自定义单元格。我已经从 NSButtonCell 子类化了我的自定义单元格。拖动不适用于纽扣电池,因为按钮不是用于拖动,而是用于照明。 我通过从 NSActionCell 中对我的自定义单元进行子分类解决了这个问题。

在下面的帖子中找到: NSTableView Drag and Drop not working

【讨论】:

    猜你喜欢
    • 2010-10-28
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多