2012-05-30 59 views
2

UIPrintInteractionControllerDelegate的文件似乎表明,你可以使用printInteractionControllerParentViewController:返回,可以用來給UIPrintInteractionController推入一個標準UINavigationControllerUIViewController,在大致相同的方式,它在完成適用於iOS的Pages.app,但儘管我嘗試這麼做,但我所做的只是將一個空的UIViewController對象推送到堆棧,而沒有其他更多。推UIPrintInteractionController到一個UINavigationController堆棧

有沒有人對如何完成這個任務有任何想法,或者它是否可以完成?

(只是要清楚,我不感興趣,在使用私有API的或類似的任何方法。)

回答

3

我有同樣的問題,試圖讓打印機選項出現在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]; 
+0

看來我的問題是我沒有使用目前的方法。謝謝! –

+0

我仍然無法讓這個工作正常,你能分享你的整個代碼嗎? –

相關問題