我正在使用UIDocumentInteractionController來顯示PDF。用戶從表格視圖中選擇要顯示的PDF。Objective-C didSelectRowAtIndexPath無法使用UIDocumentInteractionController
當我看完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];
}
我的問題是,我怎麼得到的UITableView來查看PDF後再次合作?
我就在這行此錯誤
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後再次選擇單元格不起作用。
更多的代碼
這是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];
}
}
而且DownloadPDF正在被SwitchFolders方法,當你選擇一個單元格被稱爲調用。
我用更多的代碼更新了我的問題。 – user979331
已添加完整方法 – user979331
添加了更多方法以及何時調用它們。 – user979331