LSUIElement behaves inconsistently with activateIgnoringOtherApps
Posted
by iconmaster
on Stack Overflow
See other posts from Stack Overflow
or by iconmaster
Published on 2009-12-07T03:11:02Z
Indexed on
2010/05/23
8:00 UTC
Read the original article
Hit count: 225
Specifically, it behaves inconsistently regarding text field focus.
I have an LSUIElement popping up a status menu. Within that menu there is a view containing a text field. The text field needs to be selectable -- not necessarily selected by default, but whichever.
When the status item is clicked, it triggers
[NSApp activateIgnoringOtherApps:YES];
And it works, about half the time.* The other half the status menu seems to consider itself "in the background" and won't let me put focus on the text field even by clicking on it. (I know the status item click-trigger is firing b/c there's an NSLog on it.)
Is this a bug in the way Apple handles these status items, or am I mishandling activateIgnoringOtherApps?
*In fact, it seems to fail only the first time after another app is activated. After that it works fine.
The complete snippet:
-(void)statusItemClicked:(id)sender {
//show the popup menu associated with the status item.
[statusItem popUpStatusItemMenu:statusMenu];
//activate *after* showing the popup menu to obtain focus for the text field.
[NSApp activateIgnoringOtherApps:YES];
}
© Stack Overflow or respective owner