OK, was mache ich falsch?
1. Erstellt Kakao App und AppDelegate genannt: window2AppDelegate
2. window2AppDelegate.hNew NSWindow von der Anwendung - Mission unmöglich?
#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. in xib Editor, ein Fenster zum anderen Controller angeschlossen - auf AppDelegate, Button Aktionen Tasten
4 , erstellt
#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. neue xib Datei erstellt PrefWindow Fenster IBOutlet mit Fenster von seinem Controller (auch PrefW gesetzt Controller genannt indowController) Option "Sichtbar beim Start" UNCHECKED! Ich möchte dieses Fenster auf einen Button klicken.
6. implementiert window2AppDelegate
#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. Nachdem ich Erstellen und Ausführen App: Schließen-Knopf die App schließt aber Button - zeigt mir nicht PrefWindow !? Warum und was mache ich falsch? Nicht dell mich, dass andere Fenster in Kakao Ziel-c zu zeigen, ist schwieriger als in "dumm" Java oder C#?
Haben Sie überprüft, ob 'ctrl' nicht-' nil' ist, wenn Sie '-buttonClick:' aufrufen? –
ja, wie in init, aber mit dem gleichen Ergebnis - es ist null – uniquepito