У меня два коротких вопроса:
- Как можно открыть окно после его закрытия.
- Как установить фокус на открывающемся окне.
Было бы неплохо, если бы кто-нибудь мог мне помочь!
Вот исходный код, который у меня есть, но я не знаю, как это сделать:
метод, вызывающий WindowController:
- (IBAction)openPreferences:(id)sender
{
[NSApp activateIgnoringOtherApps:YES];
if (NULL == preferences)
{
preferences = [[PreferencesController alloc] initWithWindowNibName:@"Preferences"];
}
[preferences showPreferenceWindow];
}
Это заголовок PreferencesController:
#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