简体   繁体   中英

Background app and NSTextField in NSWindow

I hide the dock icon of my Cocoa app with

ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToBackgroundApplication);

My code loads a NIB file and displays the window of that NIB ( makeKeyAndOrderFront: ) when the user clicks on a statusbar menu item. The window contains a NSTextField.

I am not able to enter text into this text field. It seems that the window is not activated correctly.

When not hiding the dock icon with the code mentioned above, text input works fine.

What may be the problem?

try this

[[NSApplication sharedApplication]  activateIgnoringOtherApps:YES];
[window makeKeyAndOrderFront:self];
[[textField window] makeFirstResponder: textField];

I've found a solution to my problem.

Basically it's making the app an agent app by default and bring back the dock icon programmatically if necessary.

See my blog for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM