Question

Simple question: I want to handle the action for cancel button pressed in my NSSavePanel. I'm using the panel with the delegate class:

NSSavePanel *save = [NSSavePanel savePanel];
[save setDelegate:self];
[save runModal];

I saw on the documentation this:

ok: This action method is invoked when the user clicks the panel’s OK button.

  • (IBAction)ok:(id)sender

but I don't know how to say to the panel to handle that method...

Thanks.

Was it helpful?

Solution

Found another solution with a non blocking panel:

[save beginWithCompletionHandler:^(NSInteger result) {
    if (result == NSFileHandlingPanelOKButton)
    {
        NSLog(@"Ok pressed.");
    }
    else if (result == NSFileHandlingPanelCancelButton)
    {
        NSLog(@"Cancel pressed.");
    }
}];

OTHER TIPS

If you're just looking to handle the cancel pressed:

 NSSavePanel *panel = [NSSavePanel savePanel]; 
 panel.delegate = self;

 if ([panel runModal] == NSOKButton) {
     // Got it, use the panel.URL field for something
 } else {
     // Cancel was pressed...
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top