NSPopover - Hide when focus lost? (clicked outside of popover)

前端 未结 2 583
你的背包
你的背包 2021-02-13 01:41

I\'m using the doubleClickAction of a NSTableView to display a NSPopover. Something like this:

NSInteger selectedRow = [da         


        
2条回答
  •  灰色年华
    2021-02-13 02:08

    the .transient flag doesn't work for me.

    However I can make things work by the following:

    1) Whenever I show my popover I make sure I activate the app (my app is a menu-bar app, so this doesn't happen automatically)

    NSApp.activate(ignoringOtherApps: true)
    

    2) When I click outside the app, then my app will be deactivated. I can detect this in the AppDelegate

    func applicationWillResignActive(_ notification: Notification) {
        print("resign active")
    }
    

    and act accordingly

提交回复
热议问题