2017-02-08 120 views
0

我正在使用Swift構建NSOutlineView。我有了這個視圖,現在我開始拖放以在視圖中移動項目。我使用This作爲我的出發點。我拖動工作,單擊並拖動輪廓,但我無法使拖放部分工作;我沒有看到水平標記,當我下降時,我什麼也沒有得到,只有嘟嘟聲。我錯過了一些明顯的東西,但我不能爲我的生活看到它。Swift:拖放在NSOutlineView

這是從我的NSOutlineViewDelegate我d & d代碼:

func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? { 

    let pp = NSPasteboardItem() 

    // working as expected here 
    if let fi = item as? FileItem { 
     pp.setString(fi.Path, forType: "public.text") 

     print("pb write \(fi.Name)") 

    } else { 
     print("pb write, not a file item \(item)") 
    } 

    return pp 
} 

func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { 

    print("validate: \(item)") 
    return NSDragOperation.move 
    // 
} 

func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool { 

    print("accept drop: \(item)") 
    return true 
} 

而且我在viewDidLoad中()註冊的阻力類型:

OutlineViewOutlet.register(forDraggedTypes: ["public.txt"]) 

任何想法讚賞,感謝。

回答

0

回答我自己的問題; ()中錯誤的類型。此作品:

OutlineViewOutlet.register(forDraggedTypes: ["public.data"])