Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphone sdk-从文档目录加载PDF_Iphone_Ios4_Pdf_Document - Fatal编程技术网

iphone sdk-从文档目录加载PDF

iphone sdk-从文档目录加载PDF,iphone,ios4,pdf,document,Iphone,Ios4,Pdf,Document,我正在使用project在我的iphone项目中显示我的pdf,但是当我试图显示来自文档而不是来自捆绑包的pdf时,我遇到了一个问题。。我认为这很简单,但有一个技巧我无法理解,因为我不是pdf阅读的大师:) 我正在使用以下代码 -(void) viewWillAppear:(BOOL)animated{ NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMas

我正在使用project在我的iphone项目中显示我的pdf,但是当我试图显示来自文档而不是来自捆绑包的pdf时,我遇到了一个问题。。我认为这很简单,但有一个技巧我无法理解,因为我不是pdf阅读的大师:)

我正在使用以下代码

-(void) viewWillAppear:(BOOL)animated{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
pListPath = [ documentDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",self.fileName]];


CFURLRef pdfURL = (CFURLRef)[NSURL fileURLWithPath:pListPath];    


//  CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("fekhElSunaI.pdf"), NULL, NULL);

pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
NSLog(@"%@",pListPath);

//    CFRelease(pdfURL);

   [self init];
}
您会注意到,我将代码放在视图中,但不会像树叶那样出现在init中。。 pdf未显示且未初始化 我使用了这个解决方案,但它也不起作用


所以这里的任何人都有一些东西可以帮助我:)

你把代码放在视图中就会出现,这可能是你的问题。在其他地方,代码可能假设代码已经被调用,并且PDF已经存在。试着把它放在init中,看看会发生什么。VIEWWILLEXPEND可能会被调用多次。

请使用此代码

- (id)init {
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];

  myPathDocs =  [documentsDirectory stringByAppendingPathComponent:@"abc.pdf"];
  pdfURL = (CFURLRef)[NSURL fileURLWithPath:myPathDocs];    
  NSLog(@"myString %@",myPathDocs);

  pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);        //        }

  size_t pageCount = CGPDFDocumentGetNumberOfPages(pdf);
}

对于您的Leavies View
init
function

问题是什么?你说你有问题。它不显示吗?你有错误吗?是的,它根本不显示,尽管它得到了页数,这就是为什么我怀疑代码的位置有问题的原因