UIPrintInteractionController 在 iOS 14 时崩溃
UIPrintInteractionController crashed in iOS 14
当在独立的单视图应用程序中呈现时,以下代码会很有用。
但是当我尝试在 UISplitViewController 上加载相同的代码时,应用程序崩溃了,但是这段代码在 iOS 13 application.But 中非常有效,在 iOS 14 中它将崩溃并发生以下异常:
Terminating app due to uncaught exception '**UIViewControllerHierarchyInconsistency',
reason: 'child view controller:<UIPrintPreviewViewController: 0x10394fa00>
should have parent view controller:<CXSTransactionSelectionViewController: 0x10389e400>
but actual parent is:<UIPrintPanelTableViewController: 0x103808200>'**
我正在使用的代码:
- (UIViewController *)printInteractionControllerParentViewController: (UIPrintInteractionController *)printInteractionController {
return [CXSCommon getParentController_iPhone];
}
- (void)Print
{
UIPrintInteractionController *controller = [UIPrintInteractionController
sharedPrintController];
if(!controller){
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %ld", error.domain, (long)error.code);
}
else
{
NSLog(@"complete");
}
};
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"My Job";
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
UIMarkupTextPrintFormatter *textPrint = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:[NSString stringWithFormat:@"<!DOCTYPE html><html><body><p><h1>Hello World</h1></p><p><h2>Hello World</h2></p><p><h3>Hello World</h3></p><p><h4>Hello World</h4></p><p><h5>Hello World</h5></p><p><h6>Hello World</h6></p></body></html>"]];
pic.printFormatter = textPrint;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [controller presentFromBarButtonItem:self.addressButton animated:YES completionHandler:completionHandler];
[controller presentAnimated:YES completionHandler:completionHandler];
}
else {
[controller presentAnimated:YES completionHandler:completionHandler];
}
}
此问题已通过注释以下代码得到解决:
UITableView *tableView = [UITableView appearance];
[tableView setSectionIndexColor:[UIColor grayColor]];
if ([[UITableView class ] instancesRespondToSelector:@selector(setSectionIndexBackgroundColor:)]) {
[tableView setSectionIndexBackgroundColor:[UIColor clearColor]];
}
[tableView setTableFooterView:[UIView new]];
[tableView setTableHeaderView:[UIView new]];
我知道这很奇怪,但我的情况已经解决了。
当在独立的单视图应用程序中呈现时,以下代码会很有用。
但是当我尝试在 UISplitViewController 上加载相同的代码时,应用程序崩溃了,但是这段代码在 iOS 13 application.But 中非常有效,在 iOS 14 中它将崩溃并发生以下异常:
Terminating app due to uncaught exception '**UIViewControllerHierarchyInconsistency',
reason: 'child view controller:<UIPrintPreviewViewController: 0x10394fa00>
should have parent view controller:<CXSTransactionSelectionViewController: 0x10389e400>
but actual parent is:<UIPrintPanelTableViewController: 0x103808200>'**
我正在使用的代码:
- (UIViewController *)printInteractionControllerParentViewController: (UIPrintInteractionController *)printInteractionController {
return [CXSCommon getParentController_iPhone];
}
- (void)Print
{
UIPrintInteractionController *controller = [UIPrintInteractionController
sharedPrintController];
if(!controller){
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %ld", error.domain, (long)error.code);
}
else
{
NSLog(@"complete");
}
};
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"My Job";
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
UIMarkupTextPrintFormatter *textPrint = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:[NSString stringWithFormat:@"<!DOCTYPE html><html><body><p><h1>Hello World</h1></p><p><h2>Hello World</h2></p><p><h3>Hello World</h3></p><p><h4>Hello World</h4></p><p><h5>Hello World</h5></p><p><h6>Hello World</h6></p></body></html>"]];
pic.printFormatter = textPrint;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [controller presentFromBarButtonItem:self.addressButton animated:YES completionHandler:completionHandler];
[controller presentAnimated:YES completionHandler:completionHandler];
}
else {
[controller presentAnimated:YES completionHandler:completionHandler];
}
}
此问题已通过注释以下代码得到解决:
UITableView *tableView = [UITableView appearance];
[tableView setSectionIndexColor:[UIColor grayColor]];
if ([[UITableView class ] instancesRespondToSelector:@selector(setSectionIndexBackgroundColor:)]) {
[tableView setSectionIndexBackgroundColor:[UIColor clearColor]];
}
[tableView setTableFooterView:[UIView new]];
[tableView setTableHeaderView:[UIView new]];
我知道这很奇怪,但我的情况已经解决了。