2011-03-03 58 views
2

我希望將PDF加載到子視圖中,然後將其推入導航堆棧。在UIWebview加載PDF文件時,現在有一個短暫的延遲。我想要的是要加載的PDF,以便滑動到屏幕上。如何在查看PDF之前加載PDF

我試過自定義下面的initWithNib方法,但沒有加載。我的想法是「如果我在初始化過程中啓動PDF加載,當我推送它時就會準備好。」可能不會。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *path = [bundle pathForResource:pdfURL ofType:@"pdf"]; 
    NSURL *fileURL = [NSURL fileURLWithPath:path]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:fileURL]; 
    [webView loadRequest:request]; 
} 
return self; 

}

這裏是我當前的實現:

在父視圖我用這個初始化PDF查看器:

  PDFViewerVC *vc = [[PDFViewerVC alloc]initWithNibName:@"PDFViewerVC" bundle:nil]; 
     vc.pdfURL = @"Service Manual RS20"; 
     vc.title = [self.list objectAtIndex:row]; 
     [self.navigationController pushViewController:vc animated:YES]; 
     [vc release]; 

在PDF查看器我用這個加載PDF:

-(void)viewDidLoad{ 
NSBundle *bundle = [NSBundle mainBundle]; 
NSString *path = [bundle pathForResource:pdfURL ofType:@"pdf"]; 
NSURL *fileURL = [NSURL fileURLWithPath:path]; 
NSURLRequest *request = [NSURLRequest requestWithURL:fileURL]; 
[webView loadRequest:request]; 
[super viewDidLoad]; 

}

謝謝。

回答