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

前端 未结 2 1654
小鲜肉
小鲜肉 2021-02-13 01:14

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

NSInteger selectedRow = [da         


        
2条回答
  •  花落未央
    2021-02-13 01:52

    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

提交回复
热议问题