mardi 5 mai 2015

My popover view controller dissapears when NSStatusBar IconView image changes.

I have a status bar app which shows a green circle in the status bar and alternates to a red circle every 10 seconds. It does this by using item.view = icon1; and item.view = icon2; to change the image. Initialised like this:

let item = NSStatusBar.systemStatusBar().statusItemWithLength(-1);
self.icon1 = IconView(imageName: "icon1", item: item);
self.icon2 = IconView(imageName: "icon2", item: item);

When you click on the green or red circle, a popover view with some settings I have made appears fine.

The problem is at each 10 second interval when the item.view changes to either the red or the green, the popover view closes and requires the user to click the green or red button again to show it.

How can I make the popover persist though status bar image changes and only disappear once the user clicks the red or green button again?

Here is my awakeFromNib() for the popover view:

override func awakeFromNib()
{
    let edge = NSMinYEdge
    let icon = self.icon
    let icon2 = self.icon2
    let icon3 = self.icon3

    let rect = icon.frame
    let rect2 = icon2.frame
    let rect3 = icon3.frame


    icon.onMouseDown = {
        if (icon.isSelected)
        {
            self.popover?.showRelativeToRect(rect, ofView: icon, preferredEdge: edge);
            return
        }

        self.popover?.close()
    }

    icon2.onMouseDown = {
        if (icon2.isSelected)
        {
            self.popover?.showRelativeToRect(rect2, ofView: icon2, preferredEdge: edge);
            return
        }

        self.popover?.close()
    }

    icon3.onMouseDown = {
        if (icon3.isSelected)
        {
            self.popover?.showRelativeToRect(rect3, ofView: icon3, preferredEdge: edge);
            return
        }

        self.popover?.close()
    }



}

}

Aucun commentaire:

Enregistrer un commentaire