Re: NSBeginAlertSheet not waiting for button to be pushed

Chad Leigh -- ObjectWerks Inc <chad+macosx-AU1NHruoRJaEK/[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Feb 7, 2010, at 3:54 AM, Christiaan Hofman wrote:

> 
> On Feb 7, 2010, at 7:41, Chad Leigh -- ObjectWerks Inc wrote:
> 
>> Hi
>> 
>> I am having an issue with NSBeginAlertSheet() on 10.6.  (Don't know how or if it works or not on 10.5 with this iteration -- this app is in production with slightly different code on 10.5 without issue)
>> 
> 
> You shouldn't be using that in Cocoa apps for a very long time now, use the NSAlert class.

It is not marked as deprecated.

> 
>> The code below lives in an object that sends a remote host a transaction and if the transaction returns an error it runs this Alert Sheet and previously (in the production code) the window passed in was [self mainWindow] which was a reference to the main app window.  I am now calling this object to do a transaction during a registration sequence and the window up is an auxiliary panel that captures registration info.  So I changed the window to be generically [NSApp keyWindow] as my thinking is that this should always use the correct window.
>> 
> 
> Definitely not, the keyWindow can be almost any window, and almost any window may not be appropriate for such a sheet. For instance some utility window.

Definitely yes.  The key window will always be the window that generated the request in my particular app.

> 
> Sheets should be attached to a window that is related to the issue reported in the sheet. If you don't have such a window, you should use an alert panel, because it's an app context (not a window context).
> 
>> Now, when it is called it does in fact put the alert sheet up on the panel.  But the function ends immediately and does not wait for the user to hit OK.  This is true with "nil" passed in for the did-end selector or a selector being passed in.  If I pass a selector in, that selector is not called.
>> 
>> Any ideas?  
>> 
>> Thanks
>> Chad
>> 
>> 
>>             NSBeginAlertSheet(
>>                [reply objectForKey:@"errorMessage"],
>>                                        // sheet message
>>                @"OK",              // default button label
>>                nil,                    // no third button
>>                nil,              //no  other button label
>>                [NSApp keyWindow],                 // window sheet is attached to
>>                self,                   // we will be our own delegate
>>                @selector(sheetDidEnd:returnCode:contextInfo:),
>>                                        // did-end selector
>>                NULL,                   // no need for did-dismiss selector
>>                nil,                 // context info
>>                [NSString stringWithFormat:@"message with code %@", [reply objectForKey:@"errorCode"]]);
>>                                        // additional text
>> 
> 
> Maybe there's another sheet? This would also be related to my remark above about where you put the sheet. Have you tried NSAlert?

There is not another sheet and the sheet is generated OK, just not done modally

Chad

> 
> Christiaan
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.