Con*_*lor 5 printing iphone cocoa-touch nsstring airprint
我真的遇到了这个问题.我不知道出了什么问题,但它吐了出来:
错误:尝试显示没有打印源(项目/项目/格式化程序/渲染器)的打印选项
如果我将其设置为打印png图像,而不是NSString的内容,则代码可以正常工作.
这是我的代码:
- (IBAction)pushPrint:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
[dateFormatter setDateFormat:@"dd/MM/YY HH:mm:ss"];
NSString* currentTime = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *path = [[NSBundle mainBundle] pathForResource:t[NSString stringWithFormat:@"Results Printout\n"
"\n"
"%@\n"
"\n"
"\n"
"%@", currentTime, pasteboard.string] ofType:nil];
NSData *myData = [NSData dataWithContentsOfFile:path];
UIPrintInteractionController *print = [UIPrintInteractionController sharedPrintController];
print.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
print.printInfo = printInfo;
print.showsPageRange = YES;
print.printingItem = myData;
void (^completionHandler)(UIPrintInteractionController *,BOOL, NSError *) = ^(UIPrintInteractionController *print,BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"houston we have a problem");
}
};
[print presentAnimated:YES completionHandler:completionHandler];
}
Run Code Online (Sandbox Code Playgroud)
您似乎想要打印一个普通的NSString
,但是您正在尝试加载一个文件路径无法生效的文件.因此,myData
很可能nil
(请与调试器确认)因此错误消息是正确的(print.printingItem
不得nil
).
要打印简单文本,请创建UISimpleTextPrintFormatter
(with initWithText:
)实例并将该实例分配给print.printFormatter
.
归档时间: |
|
查看次数: |
4318 次 |
最近记录: |