我有表视图包含文件列表,它在单击单击时推送到Web视图,正确的文件路径从表视图传递到Web视图,但Web视图加载空白页。这是我使用的代码
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ShowPDF"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PDFViewController *destViewController = segue.destinationViewController;
NSFileManager *filemgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* inboxPath = [documentsDirectory stringByAppendingPathComponent:@"Inbox"];
dirFiles = [filemgr contentsOfDirectoryAtPath:inboxPath error:nil];
destViewController.path = [documentsDirectory stringByAppendingPathComponent:[dirFiles objectAtIndex:indexPath.row]];
}
}
要加载webview,请使用以下代码
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *filePath =path;
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[pdfView loadRequest:request];
[pdfView setScalesPageToFit:YES];
NSLog(@"%@", self.pdfView);
}
需要帮助来解决此问题。
答案 0 :(得分:0)
我解决了这个问题,在下面的行
中出错destViewController.path = [documentsDirectory stringByAppendingPathComponent:[dirFiles objectAtIndex:indexPath.row]];
用下面的行替换
destViewController.path = [inboxPath stringByAppendingPathComponent:[dirFiles objectAtIndex:indexPath.row]];