我正在使用UIDocumentInteractionController来显示PDF。用户从表格视图中选择要显示的PDF。
当我完成查看PDF并单击“完成”按钮后,我的表视图将重新加载并显示。但表格视图显示为冻结,无法向上或向下滚动。所以我的didSelectRowAtIndexPath方法不起作用。
这是我的代码:
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [datasource PDFFilePath], [ffd fileFolderName]];
NSURL *URL = [NSURL fileURLWithPath:filePath];
if (URL)
{
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
[self.documentInteractionController setDelegate:self];
[self.documentInteractionController presentPreviewAnimated:YES];
}
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
return self;
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[_tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FileFolderData *ffd =
[[datasource.finalData valueForKey:
[[[datasource.finalData allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
if ([ffd isFile])
{
[_tableView setUserInteractionEnabled:NO];
}
[self performSelector:@selector(SwitchFolders:) withObject:indexPath afterDelay:0.1f];
}
我的问题是,如何在查看PDF后再次使用UITableView?
我收到此错误
Assigning to 'id<UITableViewDataSource> _Nullable' from incompatible type 'ViewController *const __strong
在这一行:
_tableView.dataSource = self;
但这可能是不相关的
其他代码:
- (void)SwitchFolders:(NSIndexPath *)indexPath
{
FileFolderData *ffd =
[[datasource.finalData valueForKey:
[[[datasource.finalData allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
if([ffd isFolder])
{
[datasource GetFilesAndFolders:[ffd fileFolderName] :NO];
[_tableView reloadData];
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
}
else if ([ffd isFile])
{
[self performSelectorInBackground:@selector(DownloadPDF:) withObject:ffd];
}
}
在选择单元格时调用此方法。使用UIDocumentInteractionController后再次选择单元格不起作用。
更多代码
- (void)PDFDownloadSuccess:(FileFolderData *)ffd
{
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [datasource PDFFilePath], [ffd fileFolderName]];
NSURL *URL = [NSURL fileURLWithPath:filePath];
if (URL)
{
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
[self.documentInteractionController setDelegate:self];
[self.documentInteractionController presentPreviewAnimated:YES];
}
}
这就是调用PDFSuccessDownload的方式:
- (void)DownloadPDF:(FileFolderData *)ffd
{
if([datasource PDFDownload_ASynch:[ffd fileFolderName]])
{
[self performSelectorOnMainThread:@selector(PDFDownloadSuccess:) withObject:ffd waitUntilDone:YES];
}
else
{
[self performSelectorOnMainThread:@selector(PDFDownloadFail:) withObject:ffd waitUntilDone:YES];
}
}
SwitchFolders方法正在调用DownloadPDF,当你选择一个单元格时会调用它。
答案 0 :(得分:0)
通过执行以下操作解决了此问题:
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[_tableView setUserInteractionEnabled:YES];
}
在PDF关闭后将UITableView的用户交互设置为“是”。