我在尝试让打印机选项出现在类似于 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];