Nueva NSWindow de la aplicación: ¿misión imposible?
OK, ¿qué estoy haciendo mal?
1. Creé la aplicación de cacao y appDelegate llamado: window2AppDelegate
2. window2AppDelegate.h
#import "PrefWindowController.h"
@interface window2AppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
PrefWindowController * ctrl;
}
@property (assign) IBOutlet NSWindow *window;
- (IBAction) buttonClick:(id)sender;
- (IBAction) buttonCloseClick:(id)sender;
@end
3. en el editor xib, ventana conectada al controlador de ventana - configurada para delegar, acciones de hacer clic en los botones
4, creado
#import <Cocoa/Cocoa.h>
@interface PrefWindowController : NSWindowController {
@private
}
@end
#import "PrefWindowController.h"
@implementation PrefWindowController
- (id)init {
self = [super initWithWindowNibName: @"PrefWindow"];
return self;
}
- (void)dealloc {
// Clean-up code here.
[super dealloc];
}
- (void)windowDidLoad {
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
@end
5. creó un nuevo archivo xib llamado PrefWindow window IBOutlet conectado a la ventana desde su controlador (también controlador configurado en PrefWindowController) Opción "Visible en el lanzamiento" ¡NO COMPROBADO! Quiero ver esta ventana haciendo clic en el botón.
6. window2AppDelegate implementado
#import "window2AppDelegate.h"
@implementation window2AppDelegate
@synthesize window;
- (id) init {
if ((self = [super init])) {
ctrl = [[PrefWindowController alloc] init];
if ([ctrl window] == nil)
NSLog(@"Seems the window is nil!\n");
}
return self;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return YES;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
- (IBAction) buttonClick:(id)sender {
// [[ctrl window] makeKeyAndOrderFront:self]; this doesn't work too :(
NSLog(@"it is here");
[ctrl showWindow:sender];
}
- (IBAction) buttonCloseClick:(id)sender {
[window close];
}
@end
7. Después de compilar y ejecutar la aplicación: closebutton cierra la aplicación pero haz clic en el botón: ¿no me mostrará PrefWindow? ¿Por qué y qué estoy haciendo mal? ¿No me dice que mostrar otra ventana en cacao Objective-C es más difícil que en Java "estúpido" o C #?