Question

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
}
Était-ce utile?

La solution

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];
}

Autres conseils

 [NSApp endSheet:sheet];
 [NSApp orderOut:nil];

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

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

}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top