OK、どうしたのですか?
1.名前の作成したココアのアプリとappDelegate: - appdelegateに設定し、buttonclickボタン
4にアクションXIBエディタ、ウィンドウコントローラに接続されたウィンドウ内のwindow2AppDelegate
2. window2AppDelegate.h新しいNSWindowアプリケーションからのミッションは不可能ですか?
#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 、
#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.(もPrefWに設定し、コントローラのコントローラからウィンドウに接続されているIBOutlet prefwindow要素のウィンドウという名前の新しいXIBファイルを作成した作成indowController)オプション "Visible At Launch"のオプションがUNCHECKED!私はこのウィンドウをbuttonclickで見たいと思う。
6.私が構築し、アプリケーションを実行した後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を実装:closebuttonアプリが、buttonclickを閉じて - 私は表示されませんprefwindow要素!なぜ、何が間違っているのですか?ココアの目的別に別のウィンドウを表示することは、 "愚かな" JavaやC#よりも難しいですか?
'-buttonClick:'に入るとき 'ctrl'が' nil'でないことを確認しましたか? –
はい、initと同様ですが、同じ結果を返します。これはnilです – uniquepito