2

I have an app that was using beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo:.

I checked Apple documentation which said it's deprecated and to use another method instead:

Presents a Save panel as a sheet with a specified path and, optionally, a specified file in that path. (Deprecated in Mac OS X v10.6. Use beginSheetModalForWindow:completionHandler: instead.)

My question is how to change this code to the new one?

//  [savePanel setRequiredFileType:@"png"];
[savePanel beginSheetForDirectory:nil 
                             file:nil  
                   modalForWindow:[self window] 
                    modalDelegate:self 
                   didEndSelector:@selector(didEndSaveSheet:returnCode:conextInfo:) 
                      contextInfo:NULL];
incoe
  • 112
  • 1
  • 2
  • 12

1 Answers1

3

You're looking for the beginSheetModalForWindow:completionHandler: method.

Example:

NSSavePanel *savePanel = [NSSavePanel savePanel];

[savePanel beginSheetModalForWindow:_window completionHandler:^(NSInteger result) {
    if (result == NSFileHandlingPanelOKButton) {
        NSURL *savePath = [[savePanel URLs] objectAtIndex:0];
    } else {
        [savePanel close];
    }
}];
Anne
  • 26,765
  • 9
  • 65
  • 71
  • Thanks Anne, tried it but when i test the save in the application it just freeze over so i guess i have to keep playing around with it till it works fine. – incoe Jul 11 '12 at 07:47
  • ok i'e figured out why isn't it working but not sure how to do it, the code used earlier used to get the if condition from another statement in another method added under it, is it possible to add something like didEndSelector:@selector(didEndSaveSheet:returnCode:conextInfo:) mentioned in the old code inside the if statement? – incoe Jul 11 '12 at 08:54
  • [savePanel close]; is not needed – Peter Lapisu Nov 20 '14 at 19:29