将整个UITableView存储在PDF文件中

时间:2011-12-14 11:43:56

标签: ios xcode uitableview pdf

我正在使用代码创建PDF文件。的工作原理。

但是:我希望我的整个UITableView(我需要滚动)在我的PDF文件中,而不仅仅是当前显示在屏幕上的视图部分。

有没有办法实现这个目标?

非常感谢。

CODE:

NSString * newFilePath = [[self documentPath] stringByAppendingPathComponent:@"Auswertung.pdf"];

CGRect page = self.view.frame;

NSDictionary * metaData = nil;

if (!UIGraphicsBeginPDFContextToFile(newFilePath, page, metaData )) {
    NSLog(@"error creating PDF context");
    return;
}

UIGraphicsBeginPDFPage();
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndPDFContext();

1 个答案:

答案 0 :(得分:2)

它并不那么容易。 UITableView 重用它的单元格,因此对整个视图的简单绘制可能只显示视口中当前可见的一些单元格。您需要手动使用单元格并在到达其他单元格后绘制它们。如果你只使用dataSource,不应该太难。请注意,如果单元格非常大,这可能会导致内存问题。

相关问题