我創建了自定義NSPanel,並使用Sheet顯示它的bengin。在它上面沒有任何按鈕可以關閉,我想在10秒後用NSTimer關閉這個面板。我怎樣才能做到這一點?使用NSTimer在可可中關閉自定義NSPanel
[[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
}
對不起,我不知道你的代碼。它用於添加NStimer還是? –