2

Sorry if this is an obvious question, but I'm new to Objective-C.

I'm making a menu bar app (doesn't show in Dock, only in menu bar), and for some reason when I open a window, it appears at the very back, behind all the other apps. I thought makeKeyAndOrderFront: would be enough, but it doesn't seem to do the trick.

So how do I make the window appear in front of other apps?

user3932000
  • 671
  • 8
  • 24
  • 1
    Can you show us your code? An example of what you have tried so far will help us answer your question. –  Jun 04 '15 at 14:46
  • @Dan I have a menu item sending `makeKeyAndOrderFront:` to the window in the MainMenu.xib file. I also read something about `setLevel:`, but I don't quite understand it. – user3932000 Jun 04 '15 at 14:50

1 Answers1

4

You also need to activate it as well.

[NSApp activateIgnoringOtherApps:YES];
[window makeKeyAndOrderFront:nil];

If this doesn't work, is your window title-less or anything like that? If so, you need to follow Cocoa/OSX - NSTextField not responding to click for text editing to begin when titlebar is hidden

Community
  • 1
  • 1
Brandon Horst
  • 1,921
  • 16
  • 26
  • That worked perfectly, thanks! And if I can ask, what does the `nil` do in `makeKeyAndOrderFront:nil`? – user3932000 Jun 04 '15 at 15:49
  • 1
    That's the `sender` object. You are supposed to pass the object responsible for doing the thing. Could be useful if you override `makeKeyAndOrderFront` someday. But the default implementation doesn't use it. More info: http://stackoverflow.com/questions/5578139/objective-c-what-is-a-id-sender – Brandon Horst Jun 04 '15 at 19:42