Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone:应用程序在显示UIButton的打印选项时崩溃_Iphone_Objective C_Cocoa Touch_Ios4 - Fatal编程技术网

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];