【问题标题】:Trouble with drag/drop in a viewbased NSTableView [duplicate]在基于视图的 NSTableView 中拖放问题 [重复]
【发布时间】:2019-07-29 15:26:39
【问题描述】:

在我的应用程序中,我实现了将文件拖放到基于视图的 NSTableview 上的可能性。 NSTableView 使用的 NSTableCellView 包含三个标签(NSTextFieldCell)和一个图像(NSImageCell)。我已经在使用的 NSTableView 的 SubClass 中直接定义了允许的 DragTypes:

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        if #available(OSX 10.13, *) {
            registerForDraggedTypes([NSPasteboard.PasteboardType.fileURL])
        } else {
            registerForDraggedTypes([kUTTypeFileURL as NSPasteboard.PasteboardType])
        }
        self.draggingDestinationFeedbackStyle = NSTableView.DraggingDestinationFeedbackStyle.regular
    }
    deinit {
        unregisterDraggedTypes()
    }

剩下的 drop 操作是用 NSTableViewDataSource 执行的,有两个函数:

func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool
func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation

到目前为止一切正常,除了一件烦人的小事:如果我在拖动过程中将鼠标移到相应行中的图像上,则会取消对该行的选择。所以简单地说:我在 TableView 的一行中的拖动过程中移动鼠标指针 - >根据需要选择该行并保持这个状态......直到我将鼠标移动到图像区域...... Swash,选择又消失了。如果我再次将鼠标从图像范围移动到该行的“其余”行,则该行再次被选中。

是不是图像也需要 DraggedTypes,并且功能也必须实现或者我忽略了一些东西(a'la“嘿,图像,让 Superview 的放置请求继续”:))? NSTableCellView 的三个标签显然不需要这个。

我注意到 NSOutlineView 有类似的行为:只要我没有看到相应条目的图像,Drag'n'Drop 就可以正常工作。

【问题讨论】:

    标签: swift nstableview nstablecellview


    【解决方案1】:

    感谢Willeke 为我指明了正确的方向!在单元格的 init 中使用 image.controlView?.unregisterDraggedTypes() 解决了该问题。

    【讨论】:

      猜你喜欢
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多