Ios UIPrintInteractionController Printingitems-解雇
我已使用此功能成功打印了一份PDF:Ios UIPrintInteractionController Printingitems-解雇,ios,objective-c,pdf,uiprintinteractioncntrler,Ios,Objective C,Pdf,Uiprintinteractioncntrler,我已使用此功能成功打印了一份PDF: -(void)printPDF{ NSString* fileName = @"Certificate.PDF"; NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
-(void)printPDF{
NSString* fileName = @"Certificate.PDF";
NSArray *arrayPaths =
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error) NSLog(@"Print error: %@", error);
};
NSData *pdfData = [[NSFileManager defaultManager] contentsAtPath:pdfFileName];
printController.printingItem = pdfData;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[printController presentFromRect:self.btnPrint.frame inView:self.btnPrint.superview
animated:YES completionHandler:completionHandler];
} else {
[printController presentAnimated:YES completionHandler:completionHandler];
}
}
当我想打印几个PDF时,我将它们放入一个数组(证书)。在我选择打印机之前,printController对话框将关闭,并且出现以下错误。
“警告:在演示或取消过程中尝试从视图控制器取消!”
我是否需要为printcontroller使用一些delgate方法,或者捕获什么
这是我打印几个PDF文档的尝试
-(void)printAllPDF{
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error) NSLog(@"Print error: %@", error);
};
printController.printingItems = certificates;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[printController presentFromRect:self.btnPrintAll.frame inView:self.btnPrintAll.superview
animated:YES completionHandler:completionHandler];
} else {
[printController presentAnimated:YES completionHandler:completionHandler];
}
}
我的错…我应该花更多的时间调试 我实际上是在我的“数组循环”中调用PrintPDF。。。 Ups…对不起:-(
-(iAction)fcPrintAllBtn:(UIButton*)发送方{
[证书删除所有对象];
适用于(Paxtype*paxArray中的pax){
[self-createPDFWithPax:pax Balloon:self.edtFlightBalloon.text Landing:self.edtLandingSite.text日期:self.edtFlightDate.text性别:pax.sBookGender PaxTitle:self.edtPaxTitle.text开始:self.edtLaunchSite.text速度:self.edtMaxSpeed.text高度:self.edtMaxAlt.text
距离:self.edtdestance.text];
NSString*fileName=@“Certificate.PDF”;
NSArray*阵列路径=
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
是的);
NSString*path=[ArrayPath对象索引:0];
NSString*pdfFileName=[path stringByAppendingPathComponent:fileName];
NSData*pdfData=[[NSFileManager defaultManager]contentsAtPath:pdfFileName];
[证书添加对象:pdfData];
[自印PDF];
- (IBAction)fcPrintAllBtn:(UIButton *)sender {
[certificates removeAllObjects];
for (Paxtype *pax in paxArray) {
[self createPDFWithPax:pax Balloon:self.edtFlightBalloon.text Landing:self.edtLandingSite.text Date:self.edtFlightDate.text Gender:pax.sBookGender PaxTitle:self.edtPaxTitle.text Start:self.edtLaunchSite.text Speed:self.edtMaxSpeed.text Altitude:self.edtMaxAlt.text
Distance:self.edtDistance.text];
NSString* fileName = @"Certificate.PDF";
NSArray *arrayPaths =
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
NSData *pdfData = [[NSFileManager defaultManager] contentsAtPath:pdfFileName];
[certificates addObject:pdfData];
[self printAllPDF]; <-----This should not be here !!!
}
[self printAllPDF]; <-----But here !!
NSLog(@"Certificates %i", certificates.count);
}