0
votes

so ive run into a strange Problem, which is kinda hard to explain, but i will try.

I have a Status Menu Item :

let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2)

it contains a NSMenu :

        let menu = NSMenu()
        statusItem.menu = menu }

now i Add custom Menue Item to it, that can contain Buttons or whatever i want:

    var newController = storyBoard!.instantiateControllerWithIdentifier("testViewController") as! testCustomViewController
    var menueItem = NSMenuItem(title: title, action: action, keyEquivalent: key)
    menueItem.view = newController.view
    statusItem.menu?.addItem(menueItem)

after that i put a testButton into the menue, and let him call an Action.

    @IBAction func testClick(sender: NSButton) {
    appDelegate.testPopover(sender)
}

so far all works just great and as intendet, ican interact with everything, and all is nice and cool. I can klick the icon, the menu opens and displays whatever i want.

But now to the Problem. If i open a Popover on the Button (which works just perfect) and the Popover is open, i cant interact with the Popover. I can Still interact with the menu and Buttons and all is cool. But as soon as i click in the Popover, everthing hides. (it doesnt crash or something, it just closes the popover, menues and so on)

I open the Popover like this. in init :

let Popover = NSPopover()
Popover.contentViewController = storyBoard!.instantiateControllerWithIdentifier("test") as! NSViewController

in the testPopoverMethod :

Popover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSMinYEdge)

So i tryed a lot of stuff, like "resignFirstResponder", "becomeFirstResponder" and ofc i tryed to change the behavior, but i just cant fix this problem.

heres a Screenshot http://imgur.com/Wj95eQw if i click anywhere in the Popover everything hides, doesnt matter where, and if theres a Button or a Text field, makes no difference...

How can i fix this ?

1
i belive i know where the problem lies. My NSMenu does count clicks in the Popover as clicks "outside" so the menu closes and with that the Popover vanishes also. But how can i make the Menu remain open ?T1663R
noone can help ? :-/T1663R

1 Answers

2
votes

Try

func testPopover(sender: AnyObject?) {
        NSRunningApplication.currentApplication().activateWithOptions(NSApplicationActivationOptions.ActivateIgnoringOtherApps)
        Popover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSMinYEdge)
    }