O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modal Windows

When a sheet is active, the user is prevented from interacting with the window from which it is presented. Modal windows are similar, except that they are presented independently of the other windows and they block user input for the rest of the application.

To present a window modally, use the runModalForWindow(_:) method on NSApplication:

f​u​n​c​ ​s​h​o​w​M​o​d​a​l​W​i​n​d​o​w​(​)​ ​{​ ​ ​ ​ ​l​e​t​ ​w​i​n​d​o​w​C​o​n​t​r​o​l​l​e​r​ ​=​ ​C​r​i​t​i​c​a​l​W​i​n​d​o​w​C​o​n​t​r​o​l​l​e​r​(​)​ ​ ​ ​ ​l​e​t​ ​a​p​p​ ​=​ ​N​S​A​p​p​l​i​c​a​t​i​o​n​.​s​h​a​r​e​d​A​p​p​l​i​c​a​t​i​o​n​(​)​ ​ ​ ​ ​l​e​t​ ​r​e​t​u​r​n​C​o​d​e​ ​=​ ​a​p​p​.​r​u​n​M​o​d​a​l​F​o​r​W​i​n​d​o​w​(​w​i​n​d​o​w​C​o​n​t​r​o​l​l​e​r​.​w​i​n​d​o​w​!​)​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required