我正在打开一个新窗口,并想实现makeKeyAndOrderFront方法:对于该窗口,我想知道要做此操作需要输入什么代码。
这是我已经打开窗口的一些代码:
文件1(第一个控制器)
#import "PreferenceController.h"
@implementation PreferenceController
- (id)init
{
if (![super initWithWindowNibName:@"Preferences"])
return nil;
return self;
}
- (void)windowDidLoad
{
NSLog(@"Nib file is loaded");
}
文件2(打开窗口的操作)
#import "Prefernces_Delegate.h"
#import "PreferenceController.h"
@implementation Prefernces_Delegate
- (IBAction)showPreferencePanel:(id)sender
{
// Is preferenceController nil?
if (!preferenceController) {
preferenceController = [[PreferenceController alloc] init];
}
NSLog(@"showing %@", preferenceController);
[preferenceController showWindow:self];
}
我尝试执行此操作的原因是,一位朋友建议解决此问题。
最佳答案
[preferenceController showWindow:self];
之后的某处:
[self.window makeKeyAndOrderFront:self];
还是您要向控制器添加方法?
// you should use a different method name, cause it's not the
// controller that is made key and ordered front.
- (void)makeKeyAndOrderFront:(id)IBAction {
[self.window makeKeyAndOrderFront:self];
}