【问题标题】:Dragging TableView Rows拖动 TableView 行
【发布时间】:2018-03-02 12:11:00
【问题描述】:

ValidateDrop 方法不起作用。

func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {

    let data = NSKeyedArchiver.archivedData(withRootObject: rowIndexes)
    pboard.declareTypes([NSPasteboard.PasteboardType(rawValue: "public.data")], owner: self)
    pboard.setData(data, forType: NSPasteboard.PasteboardType(rawValue: "public.data"))

    print("WriteRows")

    return true
}

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

    if dropOperation == .above {
        return .move
    }

    print("acceptDrop")

    return []
}

“WriteRows”已打印,但 validRow 不起作用且不打印。

在第一次尝试拖动时打印此消息。

2018-03-02 12:55:05.785644+0100 Plantilla[37119:1093734] MessageTracer:load_domain_whitelist_search_tree:73:不支持搜索树文件的格式版本号 (0)

2018-03-02 12:55:05.785702+0100 Plantilla[37119:1093734] MessageTracer:回退到默认白名单

【问题讨论】:

  • 消息是否与拖放有关? validatedRowvalidateDropprint("acceptDrop") 是同一种方法吗? validateDrop 被调用了吗?你能发布你对acceptDrop的实现吗?

标签: cocoa


【解决方案1】:

我错过了将表格视图注册到可拖动的特定允许类型的对象。找到解决方案here

tableView.registerForDraggedTypes([NSPasteboard.PasteboardType("public.data")])

【讨论】:

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