I'm trying to instantiate new windows programmactially, then configure their delegate object.
Unfortunatelly, the delegate object does not seems to receive any event once set.
I've tried to reduce my code to a short example:
AppDelegate.h
@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate>
- (IBAction) clicked:(id)sender;
@end
AppDelegate.m
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@end
@implementation AppDelegate {
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Main app window delegate works properly
[[self window] setDelegate:self];
}
// Button clicked: instantiate a new window from a specific nib (default)
- (IBAction) clicked:(id)sender {
static NSWindowController* foo;
foo = [[NSWindowController alloc] initWithWindowNibName: @"ExampleWindow"];
[[foo window] setDelegate:self];
[foo showWindow:self];
}
// Will correctly trigger for main window, but not for newly created windows
- (void) windowWillMove:(NSNotification *)notification {
NSWindow* moved = (NSWindow*)[notification object];
NSLog(@"Window %p (%@) will move", moved, [moved title]);
}
@end
I'm probably missing something obvious, but I'm unable to determine what