我有同樣的問題,試圖讓打印機選項出現在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如的本發明的方法代表將只能被稱爲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];
看來我的問題是我沒有使用目前的方法。謝謝! –
我仍然無法讓這個工作正常,你能分享你的整個代碼嗎? –