我创建了自定义 NSPanel,并使用 Sheet 显示它。它没有任何关闭按钮,我想在 10 秒后用 NSTimer 关闭这个面板。我怎样才能做到这一点?
[[NSApplication sharedApplication] beginSheet: scanningPanel
modalForWindow: window
modalDelegate: self
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
[[NSApplication sharedApplication] runModalForWindow: scanningPanel];
NSTimer *myTimer = [NSTimer timerWithTimeInterval: 10.0
target:self
selector: @selector(closePanel:) userInfo:nil
repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSModalPanelRunLoopMode];
closePanel() 函数:
-(void) closePanel: (NSTimer *) theTimer
{
NSLog(@"closePanel");
[scanningPanel abortModal]; // seems it not work
}