0

I created custom NSPanel and I show it bengin with Sheet. On it do not have any button to close, I want to close this panel with NSTimer after 10s. How can I do that?

[[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 () function :

-(void) closePanel: (NSTimer *) theTimer
{
    NSLog(@"closePanel");
    [scanningPanel abortModal]; // seems it not work
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Joson Daniel
  • 409
  • 1
  • 9
  • 18

3 Answers3

1
 [NSApp endSheet:sheet];
 [NSApp orderOut:nil];
atomkirk
  • 3,701
  • 27
  • 30
1

Try this:

[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];
}
colincameron
  • 2,696
  • 4
  • 23
  • 46
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
0

Try This : -(void) closePanel: (NSTimer *) theTimer {

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

}