1
您好我最近與Leaves api工作,我有這個問題,我需要顯示一個PDF文件,並且我的ViewController
類有一個nib文件,我實現代碼基於API示例代碼但沒有顯示任何東西!我錯過了什麼嗎?iPhone:實現Ole葉API
#import "BookViewController.h"
#import "Utilities.h"
@implementation BookViewController
/////EDITED//////////////
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
if (self = [super initWithNibName:@"BookViewController" bundle:nil]) {
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("paper.pdf"), NULL, NULL);
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
CFRelease(pdfURL);
}
return self;
}
- (void)dealloc {
CGPDFDocumentRelease(pdf);
[super dealloc];
}
- (void) displayPageNumber:(NSUInteger)pageNumber {
self.navigationItem.title = [NSString stringWithFormat:
@"Page %u of %u",
pageNumber,
CGPDFDocumentGetNumberOfPages(pdf)];
}
#pragma mark LeavesViewDelegate methods
- (void) leavesView:(LeavesView *)leavesView willTurnToPageAtIndex:(NSUInteger)pageIndex {
[self displayPageNumber:pageIndex + 1];
}
#pragma mark LeavesViewDataSource methods
- (NSUInteger) numberOfPagesInLeavesView:(LeavesView*)leavesView {
return CGPDFDocumentGetNumberOfPages(pdf);
}
- (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, index + 1);
CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(page, kCGPDFMediaBox),
CGContextGetClipBoundingBox(ctx));
CGContextConcatCTM(ctx, transform);
CGContextDrawPDFPage(ctx, page);
}
#pragma mark UIViewController
- (void) viewDidLoad {
[super viewDidLoad];
leavesView.backgroundRendering = YES;
[self displayPageNumber:1];
}
謝謝你,我將其更改爲initWithNibName,但不會再改變任何東西,你會請參閱我的編輯的問題,並檢查它 –
有什麼辦法來加載PDF無榫文件?因爲我的應用程序是Universal –
,那麼你需要一個'init'方法(而不是'initWithNibName'),那麼當你需要它的時候顯式地實例化它(從你的應用程序委託?),並將它的視圖添加到它所屬的位置你應用委託給主窗口)。你也需要在你的控制器中實現'loadView'(幾秒鐘後查看我的編輯) – sergio