我正在使用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中,而不是像init那样在init中。 pdf未出现且未初始化 我已经使用了这个LINK上的解决方案而且它无法正常工作
所以这里有人可以帮助我:)
答案 0 :(得分:0)
您已将代码放在viewWillAppear中,这可能是您的问题。在其他地方,代码可能会假设已经调用了代码,并且PDF已经存在。尝试将它放在init中,看看会发生什么。 viewWillAppear可能会被多次调用。
答案 1 :(得分:0)
使用此代码
- (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
功能