2013-08-29 3 views
0

사용자 정의 NSPanel을 작성했으며이를 시트와 함께 표시합니다. 닫기 버튼이 없어 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 
} 

답변

1

T 예 :

[NSApp beginSheet:scanningPanel modalForWindow:[self window] 
           modalDelegate:self 
           didEndSelector:nil 
            contextInfo:self]; 

NSTimer *tm=[NSTimer scheduledTimerWithTimeInterval:1.0 
              target:self 
              selector:@selector(closePanel:) 
              userInfo:nil 
              repeats:NO]; 

- (void)closePanel:(NSTimer *)theTimer 
{ 
    NSLog(@"closePanel"); 
    [NSApp endSheet:scanningPanel]; 
    [scanningPanel orderOut:self]; 
} 
0
[NSApp endSheet:sheet]; 
[NSApp orderOut:nil]; 
+0

죄송합니다. 귀하의 코드를 모르겠습니다. Add NStimer 또는? –

0

이 시도 : - (무효) closePanel : (NSTimer *) theTimer {

[scanningPanel orderOut:self]; 
[NSApp stopModal]; 

}

관련 문제