新的NSWindow从应用程序 - 任务不可能? [英] New NSWindow from application - mission impossible?
问题描述
好的,我做错了什么?
1。创建可可应用程序和appDelegate命名为:window2AppDelegate
2。 window2AppDelegate.h
OK, what am I doing wrong?
1. Created cocoa app and appDelegate named: 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。在xib编辑器中,窗口连接到窗口控制器 - 设置为appdelegate,buttonclick操作到按钮
4,创建
3. in xib editor, window connected to window controller - set to appdelegate, buttonclick actions to buttons
4, created
#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。创建名为PrefWindow窗口的新的xib文件IBOutlet从其控制器(也是控制器设置为PrefWindowController)连接到窗口选项可见的启动UNCHECKED!我想在buttonclick上看到这个窗口。
6。已实现window2AppDelegate
5. created new xib file named PrefWindow window IBOutlet connected to window from its controller (also controller set to PrefWindowController) Option "Visible At Launch" UNCHECKED! i want to see this window on buttonclick.
6. implemented 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 !?为什么,我做错了?不要告诉我在可可目标c中显示其他窗口比在愚蠢的Java或C#中更难。
7. After I build and run app: closebutton closes the app but buttonclick - won't show me PrefWindow!? Why and what am i doing wrong? Don't dell me that to show other window in cocoa objective-c is more difficult than in "stupid" Java or C#?
推荐答案
在控制PrefWindow的nib编辑器中:将文件的所有者类设置为:NSWindowController ,然后将窗口IBOutlet从文件的所有者连接到我的(preferneces)窗口 。6天的失败尝试后,google工作。
无论如何,感谢您的回复和时间!
Finally i've managed the problem! In the nib editor for PrefWindow I had to do: Set File's owner class to: NSWindowController then connect window IBOutlet from File's owner to my (preferneces) window. After 6 days of unsuccessful attempts, google works.
Anyway, thanks for all your responses and time!
这篇关于新的NSWindow从应用程序 - 任务不可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!