In my app I am displaying Print option from UIButton
using following code.
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];
}
};
I have tried following options.
[pic presentAnimated:YES completionHandler:completionHandler];
OR
[pic presentFromRect:CGRectMake(btnPrint.frame.origin.x, btnPrint.frame.origin.y, btnPrint.frame.size.width, btnPrint.frame.size.height) inView:self.view animated:YES completionHandler:comple开发者_JAVA百科tionHandler];
But it crashes with error : EXE_BAD_ACCESS
But when I tried following code for displaying print option, It works fine.
[pic presentFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES completionHandler:completionHandler];
Now, I am not using navigation controller. So I can't use this above method.
What should I do ?
Why can't you use: [self presentViewController: animated: completion:];
?
Ok. I have solved my problem.
The view
where you are going to give print
option. It should be contain navigation controller
.
So, My solution
First *first = [[First alloc] initWithNibName:@"First"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootView:@"first"];
[self presentViewController:nav animated:YES];
Its strange solution. but worked for me.
精彩评论