I'm trying to get a Login Window to display as a sheet from my MainWindow, but whenever I try to implement the AppKit methods an error always pops up for various indistinguishable reasons.
None of the online guides out there are working, when i apply their code / adapted classes to my own project they never work.
Most of the guides are heavily outdated, including the Apple Documentation. And none of them seem to be compatible with Automatic Reference Counting. Or the Xcode 4 interfaces.
Would someone be able to detail for me in full a guide, for the simplest way of displaying a sheet following a button press on the MainWindow.
Feel free to ask for more information if you need it.
Tutorial for Xcode 4
Create new project and add the following to
AppDelegate.h
andAppDelegate.m
.AppDelegate.h
AppDelegate.m
Open the
MainMenu.xib
.Use the existing
NSWindow
.Make it visible using the following button:
Create one new
NSPanel
.Add the appropriate
NSButtons
.Connect
Close
to theApp Delegate
.And select
endTheSheet
.Connect
Open
to theApp Delegate
.And select
showTheSheet
.Connect the
App Delegate
to the newNSPanel
.And select
theSheet
.Select the
NSPanel
and disableVisible At Launch
. (Essential step!)Now hit run and enjoy the result:
Things have changed in SDK 10.10 - the calls are simpler to understand I think. A parent window is in charge of launching a child NSWindow as a sheet - and then you pass this child NSWindow to NSApp to run modally. Then do the opposite to unwrap.
Displaying sheet
To display the sheet instead of calling:
You now call on the parent window:
And then to run the sheet as in modal loop, you also have to call NSApp with:
Closing Sheet
To close the sheet, call on the parent window:
Which causes the completionHandler from the above call to fire, - in which you can put a call to stop running the modal window by calling NSApp with:
Full example