Help with sheets (again)…

At the very start of my app (applicationDidFinishLaunching) I test if a critical file is available, using a method called


If the file is available, I load it. If no, I offer the choice to create a new empty one (using NSSavePanel) or find an existing --maybe moved-- , file using NSOpenPanel.

Of course, I first tell the user that the file was not found, using a sheet alert with three buttons (Quit, Create or Search). So far so good. The “Search” button launches an NSOpenPanel (a standard one, not a sheet). On return, the new path is stored into the preferences (using [NSURL path]). So far so good.

But the alert sheet is NOT dismissed. It stays on the main window, the colored ball begins to spin and I’m forced to quit.

Why is this alert not dismissed? I use a unique “disSheetEnd” handler for all my alerts, relying on a “selector” to know which alert condition launched the sheet. For other alerts, everything is fine, but this one causes problems.

This is the method:

if (returnCode == NSAlertDefaultReturn) {[self lookForExistingRegister]; }
call this:


So what? I thought it was a infinite loop, but where? the second time attempToLoadRegister is called, the path is set so no alert will occur.

I’m lost into my own code. Sob.

EDIT: I put a log into attempToLoadRegister. It is not called the second time. Where on earth is my execution pointer? Not in the main loop, certainly.

I wonder if your problem relates to passing a string for the void * parameter. Try passing the value via an ivar or property.

IAC, the docs advise agains using NSBeginAlertSheet these days.

Oh hang on…

You can’t use “==” with pointers unless you want to test if they’re the same object. Try isEqualToString:

I’m using often literal strings as contextInfo parameter and check them with the normal equation expression ( == ).
Works flawlessly in MacOS and iOS.
Maybe because a literal string constant (NSConstantString) is treated slightly different than an NSString object

I don’t thing so, as I use a pointer as selector, so it’s a pointer comparison.

BTW, I got this error – something useful?

Well, it’s getting even more weird.

I didn’t touch anything, not even relaunched Xcode, and suddenly everything works as planned.

This is worse than having found a bug and correcting it. WHY did Xcode (or my app) freeze? Is it an inner bug? Where? Will it come again? Now I feeling unsecure. And what is this “ToolbarArrangeByTemplate” error?

I could say to myself “Well, everything is cool now, it works, so let start something else”.

But I just can’t. Know the feeling?

The error message is quite clear. The error occurs if an specific (custom) image is missing in the bundle
or the path to the image is not valid

Not so much. I never used such an image, it the first time I see this name.

EDIT: to be sure, I opened the .xib as source file and searched for “ToolbarArrangeByTemplate”. No match.

Nor exists in the documentation.

I didn’t know, that the image is not a custom part of your project.

Searching google for “ToolbarArrangeByTemplate” doesn’t return significant results.
Then it might be a bug, I guess

If YOU say so, it must be one. Lucky me.

I tested it and both open and save panels worked as expected dismissing the panel.
Just for making it clear both panels are not treated as sheets

You should handle the result of runModal rather than the state of URL

 NSSavePanel *savePanel = [NSSavePanel savePanel];
 NSInteger result = [savePanel runModal];
 if (result ==  NSFileHandlingPanelOKButton) {
        // user pressed OK button    
 else {
        // user pressed Cancel button 

the “bug” refers to the “ToolbarArrangeByTemplate” message, not your sheet/panel problems

This message suddenly disappeared and my code works as it should have from the beginning: sheets are removed and the code flow executed normally.

I don’t understand. Maybe another application interferes ? I noticed than sometimes, when debugging with Xcode, I get a message from Photoshop, running in background, saying “The request cannot be completed because of a program error”. It is possible that multiple threads somewhat interact?

The message has definitely something to do with NSOpenPanel/NSSavePanel/NSPanel. When one of these dialogs are opened (not as sheet), this message is sent to the output log:

Could not find image named ‘ToolbarArrangeByTemplate’

Well, these panel DO have a toolbar indeed.

I reported this as a bug to Apple.