我正在使用Leaves项目在我的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];
}您会注意到,我将代码放在viewWillAppear中,而不是像leaves那样放在init中。我使用了这个LINK上的解决方案,但它也不起作用
所以在座的任何人有什么可以帮助我的:)
发布于 2011-09-16 01:50:01
您已经将代码放在viewWillAppear中,这可能是您的问题所在。在其他地方,代码可能假设代码已经被调用,并且PDF已经在那里。试着把它放到init中,看看会发生什么。viewWillAppear可能会被调用多次。
发布于 2012-03-11 05:17:22
使用此代码
- (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视图init函数
https://stackoverflow.com/questions/7221718
复制相似问题