【发布时间】:2011-11-13 13:18:20
【问题描述】:
我有两个简短的问题:
- 如何在关闭窗口后重新打开它。
- 如何将焦点设置在我打开的窗口上。
如果有人可以帮助我,那就太好了!
这是我到目前为止的源代码,但我不知道如何继续:
调用WindowController的方法:
- (IBAction)openPreferences:(id)sender
{
[NSApp activateIgnoringOtherApps:YES];
if (NULL == preferences)
{
preferences = [[PreferencesController alloc] initWithWindowNibName:@"Preferences"];
}
[preferences showPreferenceWindow];
}
这是 PreferencesController 的 Header:
#import <Foundation/Foundation.h>
@interface PreferencesController : NSWindowController <NSWindowDelegate>
- (void)showPreferenceWindow;
@end
这是 PreferencesController 的主要部分:
#import "PreferencesController"
@interface PreferencesController()
@end
@implementation PreferencesController
- (void)windowWillClose:(NSNotification *)notification
{
}
// display the preference window
- (void)showPreferenceWindow
{
[self.window makeKeyAndOrderFront:NSApp];
// TODO: window should be focused and if the user press the close button it should be displayed again
}
- (void) dealloc
{
[super dealloc];
}
@end
【问题讨论】:
标签: objective-c macos cocoa window