NSAlert Sheet Not Having Focus

EDITED TO ADD: Several months later, I ran into this same bug again!

I had an issue where if I used
beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:
to put up an NSAlert as a sheet inside a window, and I was not running on the main thread, the sheet would not have focus. I’m not sure exactly why, but this solution worked for me: Put the call to beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo: inside another method, showMyAlert, then use performSelectorOnMainThread:withObject:waitUntilDone: to make sure showMyAlert is called on the main thread.

Strangely, if i used runModal to display the NSAlert as a separate modal window, it would have focus.

The whole incident feels funny to me. I suspect there may be some deeper issue at work that I am not aware of. When I have time to investigate further I shall update this post. Unfortunately I don’t have time to look into ‘solved’ bugs today.

Advertisements
Explore posts in the same categories: Cocoa, Debugging, MacOSX, NSAlert, Programming

One Comment on “NSAlert Sheet Not Having Focus”


  1. […] I remembered having encountered weirdness with NSAlert sheets before. The symptoms were different (previously the alert didn’t have focus), but the same solution […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: