NSTableView: detecting a mouse click together with the row and column

后端 未结 6 547
Happy的楠姐
Happy的楠姐 2020-12-08 01:10

I\'m trying to detect when a mouse click occurs in an NSTableView, and when it does, to determine the row and column of the cell that was clicked.

So far I\'ve tried

6条回答
  •  长情又很酷
    2020-12-08 01:36

    Just in case someone was looking for it in SWIFT and / or for NSOutlineView.

    Based on @Peter Lapisu instructions.

    class MYOutlineViewDelegate: NSOutlineView, NSOutlineViewDelegate,NSOutlineViewDataSource{
    //....
    }    
    extension MYOutlineViewDelegate{
        func outlineView(outlineView: NSOutlineView, didClickTableRow item: AnyObject?) {
            //Click stuff
        }
    
        override func mouseDown(theEvent: NSEvent) {
            let globalLocation:NSPoint  = theEvent.locationInWindow
            let localLocation:NSPoint  = self.convertPoint(globalLocation, fromView: nil)
            let clickedRow:Int = self.rowAtPoint(localLocation)
    
            super.mouseDown(theEvent)
    
            if (clickedRow != -1) {
                self.outlineView(self, didClickTableRow: self.itemAtRow(clickedRow))
            }
        }}
    

提交回复
热议问题