Question

The loadFile method starts a NSTimer to load an process a file over time without blocking the application in a while loop. This timer is not firing with the first bit of code, and is with the second bit. The issue is the second bit shows the sheet as a panel style window, not as a sheet.

How do I get a sheet that can still do work?

Show Sheet but no work is done

[self.sheetView loadFile:filename];
[[NSApplication sharedApplication] beginSheet: self.sheetView
                               modalForWindow: self.window
                                modalDelegate: self
                               didEndSelector: nil
                                  contextInfo: nil];
[[NSApplication sharedApplication] runModalForWindow: self.sheetView];

Show window and work is done

NSModalSession session = [NSApp beginModalSessionForWindow:self.sheetView];
NSInteger result = NSRunContinuesResponse;

[self.sheetView loadFile:filename];

// Loop until some result other than continues:
while (result == NSRunContinuesResponse)
{
    // Run the window modally until there are no events to process:
    result = [NSApp runModalSession:session];

    // Give the main loop some time:
    [[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
}

[NSApp endModalSession:session];
Was it helpful?

Solution

Is there a reason why NSThread can't be used? That's the obvious answer ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top