ios - 文件路径为零

标签 ios filepath

大家好,我是 ios 的新手

这是我的代码

       NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
       NSString  *documentsDirectory = [paths objectAtIndex:0];
       NSString *comicbook_id = [[NSUserDefaults standardUserDefaults]stringForKey:@"comicbook_id"];
       NSString  *filePath = [NSString stringWithFormat:@"%@/book_%@.pdf", documentsDirectory,comicbook_id];



       documentsDirectory = [documentsDirectory stringByAppendingPathComponent:filePath];

       NSLog(@"date==>%@",documentsDirectory);
       ***here i am getting path***
       ReaderDocument *document = [ReaderDocument withDocumentFilePath:documentsDirectory password:nil];
      NSLog(@"date==>%@",document); 

*****here i am getting <nil>***** 


       if (document != nil) {

           ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
           readerViewController.delegate = self;
           readerViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
           readerViewController.navigationController.navigationBar.tintColor = [UIColor blackColor];

           readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
           readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;

           [self presentViewController:readerViewController animated:YES completion:nil];
} 

最佳答案

而不是这个:

NSString  *filePath = [NSString stringWithFormat:@"%@/book_%@.pdf", documentsDirectory,comicbook_id];

使用

 NSString  *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString  stringWithFormat:@"book_%@.pdf",comicbook_id]];

关于ios - 文件路径为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20392236/

相关文章:

PHP - 如何将大量文件路径存储到 MySQL 数据库?

ios - 自动布局 : understanding the behavior of attributes and items

python - FileNotFoundError:[WinError 2]尝试使用pysndfx时,系统找不到指定的文件

c++ - 如何解析文件路径

php - Laravel - 如何获取文件的路径名

c - 操作给定路径的递归函数

ios - 为 iOS 项目编译 libtiff 以包含 64 位架构

ios - iOS-如何将混合音频合成导出到最小文件大小的文件?

iOS 核心数据一对一自反关系谓词

ios - 有没有办法知道用户在使用我的应用程序时是否正在通话?