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
Post a Comment