iPhone:应用程序在显示UIButton的打印选项时崩溃
在我的应用程序中,我使用以下代码从iPhone:应用程序在显示UIButton的打印选项时崩溃,iphone,objective-c,cocoa-touch,ios4,Iphone,Objective C,Cocoa Touch,Ios4,在我的应用程序中,我使用以下代码从ui按钮显示打印选项 UIPrintInfo* printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = NSLocalizedString(@"Offerings", @""); UIMarkupTextPrintFormatter *formatter = [[UIMar
ui按钮显示打印选项
UIPrintInfo* printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = NSLocalizedString(@"Offerings", @"");
UIMarkupTextPrintFormatter *formatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:@"Share"];
formatter.startPage = 0;
CGFloat margin = 72.0f * 0.1f;
formatter.contentInsets = UIEdgeInsetsMake(margin, margin, margin, margin);
UIPrintInteractionController* pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
pic.showsPageRange = YES;
pic.printInfo = printInfo;
pic.printFormatter = formatter;
[formatter release];
void (^completionHandler)(UIPrintInteractionController*, BOOL, NSError*) = ^(UIPrintInteractionController* printController, BOOL completed, NSError* error)
{
if (!completed && error)
{
UIAlertView* alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Printing Error", @"")
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
};
我试过以下几种选择
[pic presentAnimated:YES completionHandler:completionHandler];
或
但是它崩溃了,出现了错误:EXE\u BAD\u ACCESS
但当我尝试使用下面的代码显示打印选项时,效果很好
[pic presentFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES completionHandler:completionHandler];
现在,我没有使用导航控制器。所以我不能用上面的方法
我该怎么办?为什么不能使用:[self-presentViewController:animated:completion:]代码>?正常。我已经解决了我的问题
视图
您将在其中提供打印
选项。它应该包含导航控制器
那么,我的解决方案是什么
First *first = [[First alloc] initWithNibName:@"First"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootView:@"first"];
[self presentViewController:nav animated:YES];
这是一个奇怪的解决方案。但是对我有用。请再加上一些代码好吗?整个方法。@Dylan:检查我更新的问题。要打印,我们必须使用UIPrintInteractionController
的对象,即pic
。它只包含上述三种方法。它将处理其他事情,如打印机选择
,页数
等。好的,我假设您有UIPrintInteractionController*pic代码>在.h文件中的某个位置。但是在您尝试这些方法之前,您是否有pic=[[UIPrintInteractionController alloc]init]代码>?不,它只是需要sharedPrintController
,我已经用同样的编码完成了。查看问题中的可用性尝试将该行更改为:UIPrintInteractionController*pic=[[UIPrintInteractionController sharedPrintController]alloc]init]代码>点击escape,光标正好经过init,并在init方法上获得一个战利品。有很多。
First *first = [[First alloc] initWithNibName:@"First"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootView:@"first"];
[self presentViewController:nav animated:YES];