将UIPrintInteractionController推送到UINavigationController堆栈

时间:2012-05-30 15:55:24

标签: objective-c ios airprint

UIPrintInteractionControllerDelegate的文档似乎建议您使用printInteractionControllerParentViewController:返回可用于将UIViewController推送到标准UIPrintInteractionController的{​​{1}}堆栈,与在Pages.app for iOS中完成的方式非常相似,但是尽管我尝试这样做,但我设法做的就是将空UINavigationController对象推送到堆栈,而不是其他很多。

是否有人对如何做到这一点有任何想法,或者是否可以完成它?

(为了清楚起见,我对使用私有API等的任何方法都不感兴趣。)

1 个答案:

答案 0 :(得分:3)

我尝试让打印机选项出现在类似于Pages的NavigationController中时遇到了同样的问题。
重要的是实现UIPrintInteractionControllerDelegate的printInteractionControllerParentViewController以返回NavigationController。 该方法仅从UIPrintInteractionController的当前方法调用 Apple docs on UIPrintInteractionControllerDelegate

一些示例代码:

// Just some code to return a UIPrintInteractionController
// Important to set delegate to self
- (UIPrintInteractionController *)printContent {
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
if  (pic && [UIPrintInteractionController canPrintURL:[self fileToPrint]]) {
    pic.delegate = self;
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"OutputFile";
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    pic.printInfo = printInfo;
    pic.showsPageRange = YES;
    pic.printingItem = self.fileToPrint;
}
return pic;
}

实现委托的printInteractionControllerParentViewController方法。

// Implement the delegate method simply to return navigationController
- (UIViewController *)printInteractionControllerParentViewController:(UIPrintInteractionController *)printInteractionController{
return self.navigationController;
}

只有在运行UIPrintInterfaceController的Present方法时才会调用委托,例如presentFromRect:

// Need to call a present method to invoke the delegate method
[[self printContent] presentFromRect:[self.view frame] inView:self.view animated:NO completionHandler:completionHandler];