Printing a UITableView with screen content?

Hi, I have an iOS app that has the ability to print a UITableView. However, only one part of the displayed table is printed. Is there a way to print the entire view of the table, even if it is not already drawn?

Here is the code I use for printing:

UIGraphicsBeginImageContext(self.mainTableView.contentSize); [self.mainTableView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIPrintInteractionController *printer = [UIPrintInteractionController sharedPrintController]; printer.printingItem = viewImage; UIPrintInfo *info = [UIPrintInfo printInfo]; printer.printInfo = info; UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) { if (!completed && error) NSLog(@"FAILED! due to error in domain %@ with error code %u: %@", error.domain, error.code, [error localizedDescription]); }; UIButton * printButton = (UIButton *)sender; if(UIUserInterfaceIdiomPad == [[UIDevice currentDevice] userInterfaceIdiom]){ [printer presentFromRect:printButton.frame inView:self.view animated:YES completionHandler:completionHandler]; } else { [printer presentAnimated:YES completionHandler:completionHandler]; } 
+4
source share
1 answer

There is a lot of discussion about this problem. Two examples:

SO: Screenshot from UITableView

SO: How to take a screenshot from the screen of the entire view, including parts from the screen

The problem is that UITableViews are reusing their cells. I think the most common approaches are:

  • Scroll programmatically to different parts of your UITableView, take various screenshots and merge them again.
  • Resize the UITableView so that it is so large that all cells fit into it. WARNING: This quickly leads to memory problems (reusing cells is no longer used), so just do this for screenshot purposes and if the number of your cells is not so large.
+3
source

Source: https://habr.com/ru/post/1402705/


All Articles