[英]iphone sdk -Loading PDF from document directory
我正在使用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中。.pdf没有出现并且没有初始化,我使用了此LINK上的解决方案,但它也不起作用
所以这里的任何人都可以帮助我的事情:)
您已将代码放入viewWillAppear中,这可能就是您的问题。 在其他地方,该代码可能假定该代码已经被调用,而PDF已经存在。 尝试将其放入init中,看看会发生什么。 viewWillAppear可能会被调用多次。
使用此代码
- (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
功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.