Re: NSBeginAlertSheet not waiting for button to be pushed

Kyle Sluder <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Sun, Feb 7, 2010 at 11:16 AM, Chad Leigh -- ObjectWerks Inc
<chad+macosx-AU1NHruoRJaEK/[email protected]> wrote:
> I have read that.   As your quote said, "You can use the Application Kit's functional API for alert sheets."  It is not deprecated and fully supported at the moment.  Most of this app's code is from 2003 and this bit dates from that time.  I am just modifying a little where it gets called from with a new set of registration panels.

"It's not deprecated" is different from "there's a better way of doing
this which is preferred for new code." Since you are working with
existing code (a point which either did not come up or eluded me), it
makes a ton more sense to continue using NSBeginAlertSheet.

> Do you have any ideas on why it  may not be modal and wait for the OK button? What might be the cause of that?

Sheets don't run modally. That's their whole purpose as a functional
UI element; they only block the window they're attached to. This means
that NSBeginAlertSheet must be an asynchronous API; that's why you
pass it a delegate.

> Not in  this app.  Those panels cannot trigger the call that includes this particular alert sheet and the keyWindow call.  The utility function that is being called is in a non GUI library and makes a network call that can fail or return an error code from the remote server.  This utility class has no clue what the current window is.  However, it is only called by my apps windows, so to speak, and will never be called when some other window like a system panel is up.  It cannot be triggered that way.

If your utility class is acting asynchronously (I really hope so;
blocking the main thread waiting for network operations to complete
will cause beachballing and a horrible user experience), then you
cannot guarantee what window is key at the time you call
NSBeginAlertSheet. I could perform the action that triggers the
network operation, switch to a different window in your app, and then
some number of seconds later your network communications utility
object gets the timeout and displays the sheet.

The correct solution would be to communicate to the utility object
"Here is the window upon which you should display your sheet in the
event of an error." Alternatively, since you seem to desire modal
operation, you could just use an alert panel instead of a sheet.

> I am explicitly choosing the window as best as the routine knows which is the keyWindow.

See above. I meant "explicitly choose a specific window."

--Kyle Sluder
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.