osx - swift unhide buttons in one column if mouse is over row -




i working swift 4 osx. have view based nstableview 4 columns. cells in each column has got same custom cell class:

class customcell: nstablecellview {       @iboutlet weak var btninfo: nsbutton!      private var trackingarea: nstrackingarea!       override func awakefromnib() {         super.awakefromnib()          self.trackingarea = nstrackingarea(             rect: bounds,             options: [.activealways, .mouseenteredandexited],             owner: self,             userinfo: nil         )         addtrackingarea(trackingarea)     }       override func mouseentered(with event: nsevent) {         super.mouseentered(with: event)             btninfo.ishidden = false     }      override func mouseexited(with event: nsevent) {         super.mouseexited(with: event)             btninfo.ishidden = true     }   } 

now realize following situation:

if user goes mouse on row, btninfo should visible , hide again, mouse leaves row.

problem (with code above), apps crashes, because btninfo nil

logically: because button in column 4 available. in other columns nil.

how can solve this?

the solution add nstrackingarea entire view, not individual cells. on entire table view, can mouse move events, take nsevent's locationinwindow. nstableview has method row(at point: nspoint) -> int can current row should highlighting button.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -