0

我需要处理 NSFontPanel 已关闭。发生这种情况时,是否有任何方法被调用?谢谢回复。

4

1 回答 1

2

NSFontPanel 是 NSPanel 的子类,NSPanel 是 NSWindow 的子类。NSWindow 有许多委托方法,它们会通知您窗口状态的变化。

在您的窗口控制器或应用程序委托中,声明与 NSWindowDelegate 的一致性,然后获取字体面板并将其委托设置为控制器对象。最后,-windowWillClose:在控制器对象中实现,并在那里采取您需要的任何操作。

例如:

/* AppDelegate.h */
@interface AppDelegate : NSObject <NSWindowDelegate>
@property (assign) IBOutlet NSWindow *window;
@end

/* AppDelegate.m */
@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
  NSFontPanel *fp = [[NSFontManager sharedFontManager] fontPanel:YES];
  fp.delegate = self;
}

- (void)windowWillClose:(NSNotification *)notification
{
  if(notification.object == [[NSFontManager sharedFontManager] fontPanel:NO])
  {
    /* Handle font panel close here */
    NSLog(@"Font panel closing");
  }
}

@end
于 2013-05-30T18:38:09.317 回答