アプリの奇妙な動作に気づき、それを修正する方法が見つかりません。カスタムNSTableRowViewとドラッグ アンド ドロップをサポートするNSOutlineViewがあります。
アイテム(ファイルなど)を最初にoutlineviewにドラッグすると、正しいハイライトが描画されます( drawDraggingDestinationFeedbackInRectをオーバーライドしました)が、2回目のドラッグでこの青いハイライトが表示され、ビュー階層をデバッグすると、NSViewが行に追加されていることがわかります.
何が起こるかを正確に示す小さなアニメーションを添付しました(同じ NSTableRowView でNSTableViewも追加しました):
上:NSOutlineView
下:NSTableView
ビューの階層 (NSOutlineView の場合):
これがNSTableRowViewの私のコードです
import Cocoa
class TestRowView: NSTableRowView {
override func drawSelectionInRect(dirtyRect: NSRect) {
NSColor.yellowColor().setFill()
NSBezierPath(rect: self.bounds).fill()
}
override func drawDraggingDestinationFeedbackInRect(dirtyRect: NSRect) {
NSColor.greenColor().setFill()
NSBezierPath(rect: self.bounds).fill()
}
}
NSOutlineViewのデータソースとデリゲート メソッドは次のとおりです。
func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
return item == nil ? allItems.count : 0
}
func outlineView(outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool {
return false
}
func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
return allItems[index]
}
func outlineView(outlineView: NSOutlineView, viewForTableColumn tableColumn: NSTableColumn?, item: AnyObject) -> NSView? {
return outlineView.makeViewWithIdentifier("DataCell", owner: self)
}
func outlineView(outlineView: NSOutlineView, rowViewForItem item: AnyObject) -> NSTableRowView? {
return TestRowView()
}
func outlineView(outlineView: NSOutlineView, heightOfRowByItem item: AnyObject) -> CGFloat {
return 60.0
}
func outlineView(outlineView: NSOutlineView, objectValueForTableColumn tableColumn: NSTableColumn?, byItem item: AnyObject?) -> AnyObject? {
return item
}
func outlineView(outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: AnyObject?, childIndex index: Int) -> Bool {
return true
}
func outlineView(outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: AnyObject?, proposedChildIndex index: Int) -> NSDragOperation {
return .Copy
}
私が試したこと:
NSOutlineView をサブクラス化し、acceptsFirstResponder をオーバーライドする
backgroundStyle のオーバーライド
- 別の selectionHighlightStyle を試しました
- NSTableViewDraggingDestinationFeedbackStyleNone を使用