The results are pretty easy to replicate.
- Create a new Xcode project called TestWindow.
- XIB not storyboard.
- Objective-C
- Set the project’s scheme to turn off Metal API validation.
- Set Build Options to NO ARC under Objective-C options.
- Delete the Main Menu window.
- Create a new window object called GoWindow. And add a window to it.
- Set File’s Owner of the AppDelegate object in Placeholders to AppDelegate.
- Drag a Scrollable Text View from the Library to the Window
- Connect an IBOutlet NSWindow in AppDelegate to the window.
- Connect an IBOutlet NSScrollview in AppDelegate to the scrollview in the window.
- Connect an IBOutlet NSTextView in AppDelegate to the textView in the ScrollView in the window.
- In AppDelegate, create an IBAction method to makeWindow.
- Add a menu item called makeWindow to the AppDelegate.
- Wire the menu item to the IBAction in AppDelegate.
- Create a method in AppDelegate called
makeWindowContinued. - Add a breakpoint to an
NSBeep();inside themakeWindowContinuedmethod. - Add
[self performSelector:@selector(makeGoWindowContinued) withObject:nil afterDelay:1];to the AppDelegate method. - Run the app.
- The breakpoint will trigger allowing you to see that the three outlets and not being set.
- Here is the resultant AppDelegate.h code:
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
IBOutlet NSWindow *theDocumentWindow;
IBOutlet NSScrollView *theDocumentWindowScrollView;
IBOutlet NSTextView *theDocumentWindowTextView;
NSWindowController *myDocumentWindowController;
}
- (NSWindowController *)myDocumentWindowController ;
- (void)set_myDocumentWindowController:(NSWindowController *)t;
- (IBAction)makeWindow:(id)sender;
- (void)makeGoWindowContinued;
@end
And the resultant AppDelegate.m code:
#import "AppDelegate.h"
@interface AppDelegate ()
@property (strong) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
- (NSWindowController *)myDocumentWindowController {return myDocumentWindowController;}
- (void)set_myDocumentWindowController:(NSWindowController *)t {[t retain]; [myDocumentWindowController release]; myDocumentWindowController = t;}
- (IBAction)makeWindow:(id)sender
{
if (![self myDocumentWindowController]) {
[self set_myDocumentWindowController:[[NSWindowController alloc] initWithWindowNibName:@"GoWindow"]];
}
[[[self myDocumentWindowController] window] setTitleWithRepresentedFilename:@"Untitled"];
[[[self myDocumentWindowController] window] center];
[[[self myDocumentWindowController] window] makeKeyAndOrderFront:self];
[self performSelector:@selector(makeGoWindowContinued) withObject:nil afterDelay:1]; // wait for window to appear
}
- (void)makeGoWindowContinued
{
NSBeep();
}
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
// Insert code here to tear down your application
}
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
{
return YES;
}
I'm not sure File's Owner is correct, maybe I need to set a delegate? Don't know.