Is there a event in swift for when a "Open" Dialog disappears? I need to update my viewController when this happens. I am having a hard time correlating the "Open" in appDelegate to anything on the ViewController.
How are you displaying the Open dialog? Are you using the NSOpenPanel?
If so, you can just update your view after the call to run the NSOpenPanel (with runModal())
Related
Hello all you smart people! I am very new to Xcode 8 and Swift3, and am bringing a new meaning to the phrase 'killer app'. It'll kill me before it gets a chance to provide my pension!!! :-)
My OSX app is a stay resident app in the top right of the apple menu (info.plist set to Application is Agent(UIElement)= True). The main function of the app, executing an applescript, works fine. It is run from the app menu icon or key combo. I've added an 'about' window and the window appears if I select 'about' from the App menu and it closes if I click the red circle. However I can't seem to get an (interface) close button to close the window.
The 'about' window is generated from an NSMenuItem in AppDelegate.swift as in the code below. All I'm trying to do is close said window with a close button in the (viewcontroller)interface. It's that simple but no matter what I try I cannot link the close button in the Storyboard viewcontroller to an IBAction in viewcontroller.swift so as to add window!.close. The only option given is a 'represented object' binding. It's not possible to link to an IBAction in AppDelegate.swift either.
t must be something to do with the way the window is generated because if I build an app with a normal apple menu the interface buttons will link to actions in the code. If anyone can help please email me at pauljvallance#icloud.com and I can send you the Xcode 8.2.1 project and Swift3 code. Best regards, Paul
func windowAbout(sender: NSMenuItem){
let mainStoryboard = NSStoryboard.init(name: "Main", bundle: nil)
myWindowController = mainStoryboard.instantiateController(withIdentifier: "aboutWindowController") as!
NSWindowController
myWindowController.showWindow(self)
}
Xcode 8 appears to have introduced a bug that prevents you from making connections by dragging from an Interface Builder element to a view controller method when the method in question is defined in a class extension. You can however create the desired connection by dragging from your method to the relevant UI element in Interface Builder:
so i have a simple NSMenu. It is attached to a Status Item Button.
When i click the Button it pops Open.
Now my Problem is that as soon as i click outside of the NSMenu, it closes. How can i avoid that ?
I did try many things but cant get that to work.
The reason i need that is that when the user clicks something in the NSMenu, another window opens, and while this window is open i also want the NSMenu to stay open. But it just does not work.
I feel like its impossible.
Many Thanks in advance.
I believe you have to create a custom view that pops up but something that could be done natively with just NSMenu.
Hi I implemented an NSPopover in one of my apps, but the popover will not close. I'm guessing that it should close once I click something else, but its not. I know that there's a close popover action but that only works for a different button. How can I make it look to see that the popover is open and when it is open to close the popover when I press the same button?
I solved the problem!
First go ahead and click your .xib file.
Where you see the first responder box and files owner - click on the popover.
On the sidebar go to the attributes center
Change the behavior from Application-Defined to Transient and it should work!
That should make the popover disappear once someone has clicked outside the popover.
Another way to close the popover is to have a separate button.
Just add another NSButton and then link it to the popover on the sidebar and set it to Received actions -> perform close:
I'm trying to determine when an NSOpenPanel is closing before it actually closes. I need to do this so I can overlay another window with a screenshot of the open panel on top of it to be animated. Unfortunately, all the notifications that you seem to be able to access seem to fire AFTER the window's already been closed. This leads to a jarring stutter before you start your transition.
I've tried:
- using NSWindow delegate methods on the open panel (apparently, none of the NSWindow delegate methods work)
- monitoring panel:userEnteredFilename:confirmed: (not called)
- showing the dialog with a callback (callback happens AFTER the panel disappears)
You should register your controller as the open panel's delegate and then implement the -panel:isValidFilename: delegate method. This method will be called just before the open dialog closes.
You should return YES from the method if you just want the notification. Returning NO allows you to prevent the open dialog from being closed.
Another way to handle this was to look through NSOpenPanel's subviews for the Cancel button and swap yourself in as the target/action. This is what i ended up doing.
I have an NSWindow that I defined in interface builder. I want to make it so that when the user clicks a button, it opens a new instance that NSWindow. Do I have to subclass NSWindow or something?
If you created the window in IB and it's in your main nib file, you cannot create a "new instance" each time you press a button. When you create an object in the nib file, an instance is actually created by IB and then archived into the nib file, so you get that instance. Assuming your window is wired to a variable named auxWindow on the same object that responds to your button click, and the action message is named buttonClick, you could do something like this to show it:
-(IBAction)buttonClick:(id)sender {
if(! [auxWindow isVisible] )
[auxWindow makeKeyAndOrderFront:sender];
}
This will cause the aux window that you defined in IB to appear on the screen and become the key window (and foremost window in the application). Please note, however, that if you intend to reuse this window, you must uncheck the box in the IB Inspector that says Release on Close, otherwise you will get an access violation the next time you click the button.
This is a simple answer to your basic question, but window programming can be quite complicated and is usually very specific (for instance, do you really want a panel for what you're doing?)... so I strongly suggest that you read the Window Programming Guide for more information on this topic, and then ask very specific questions here when you get stuck.
Put the window in its own nib file, then load the nib file each time. You should use NSWindowController for loading the nib, like NSDocument does.