0

In Cocoa, my application's main window has a button. How can I make it so when you click it, a new window will be generated and set focus to such window so that the main window can not be clicked or interacted with at all? This new window will have a textfield and a submit button. You click it and the window is supposed to close and send the textfield's data back to the main window (and it will recover focus as well).

I found this: How to open a new window on button click in Cocoa Mac Application?

But the answer doesn't seem to be working for me. The function showWindow doesn't seem to be recognized...

Community
  • 1
  • 1
Saturn
  • 17,888
  • 49
  • 145
  • 271

1 Answers1

0

You're trying to create a modal window.

You can see the documentation at http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/WinPanel/Concepts/UsingModalWindows.html for the full details.

Assuming you have created the window in your nib and can access it via an Outlet, you can call

[NSApp runModalForWindow:myWindowOutletVariable];

to make it modal like you want.

James Williams
  • 1,861
  • 1
  • 15
  • 21
  • 1
    …and bear in mind that modal windows [should be avoided if possible](http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AppleHIGuidelines/Windows/Windows.html#//apple_ref/doc/uid/20000961-BACFBACB). Modal windows are not expected behaviour on Mac OS X. Use a [sheet](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Sheets/Sheets.html) instead. – Rob Keniger Nov 22 '11 at 23:31