开发者

NSPrintOperation hangs application

I have an application that hangs whenever I call NSPrintOperation.

I have a view that is creates a separate class (UIView) like this:

PBPrintImage *printImage = [[PBPrintImage alloc] init];
printImage.image = finalImage;
[printImage printWithNoPanel:self];

Then inside PBPrintImage I have the following method:

- (void)printWithNoPanel:(id)sender {
    CGSize picSize = CGSizeMake(300, 446);
    NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];

    NSRect imageRect = NSRectFromCGRect(CGRectMake(0, 0, picSize.width, picSize.height));
    NSImageView *imageView = [[NSImageView alloc] initWithFrame:imageRect];
    [imageView setImage:image];

    NSPrintOperation *op = [NSPrintOperation printOperationWithView:imageView printInfo:printInfo];
    [op setCanSpawnSeparateThread:YES];
    [op setShowsPrintPanel:NO];
    [op runOperation];
}

If I don't call it the application works as suspected. And I've tried calling it with and without setCanSpawnSeparateThread:. How do I set it up so it has to be in a开发者_StackOverflow中文版 separate thread and therefore doesn't mess up the regular flow of the application?

It does print, but that is only half of the job.


The application should show a modal print dialog (and start a modal run loop), so I would not call it "hanged". It returns to the normal main thread flow as soon as you hit Ok or Cancel.

As for the setCanSpawnSeparateThread: issue, it only kicks in when the print dialog is displayed as a sheet, so you need to call it like this: `[op runOperationModalForWindow:window delegate:self didRunSelector:@selector(_printOperationDidRun:success:contextInfo:) contextInfo:nil]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜