0

我按照 raywenderlich 教程创建 PDF。http://www.raywenderlich.com/6818/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-2。我需要顶部的 NavBar 和底部的 Tab。我在底部得到标签,但在顶部缺少导航栏。PDF 接管了底部标签栏顶部的所有内容。任何帮助是极大的赞赏。

- (void)viewDidLoad
{
     NSString* fileName = [self getPDFFileName];

     NSMutableDictionary *dataDict = [NSMutableDictionary new];
     NSNumber *tripId = (NSNumber *)[Helper getValueForKeyFromGlobalDictionary:TRIP_ID];
     [dataDict setValue:[self retrieveTimings:[tripId intValue]] forKey:NEWTRIP_MO];
     [dataDict setValue:[self retrieveStops:[tripId intValue]] forKey:TIME_MO];
     [dataDict setValue:[self getCompanyInfo:[tripId intValue]] forKey:COMPANY_MO];
     [dataDict setValue:[self getTripInfo:[tripId intValue]] forKey:TRIP_MO];
     [dataDict setValue:[self getDriverInfo:[tripId intValue]] forKey:DRIVERS_MO];
     [dataDict setValue:[self getLoadInfo:[tripId intValue]] forKey:LOAD_MO];
     [PDFRenderer drawPDF:fileName withData:dataDict];
     [self showPDFFile];
     [super viewDidLoad];

     NSLog(@"Testing");
 }

-(void)showPDFFile
{
    NSString* fileName = @"Invoice.PDF";

    NSArray *arrayPaths =
    NSSearchPathForDirectoriesInDomains(
                                    NSDocumentDirectory,
                                    NSUserDomainMask,
                                    YES);
     NSString *path = [arrayPaths objectAtIndex:0];
     NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];

     UIWebView* webView = //[[UIWebView alloc] initWithFrame:view2.frame];
     [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

     NSURL *url = [NSURL fileURLWithPath:pdfFileName];
     NSError *error = [[NSError alloc] init];
     NSLog(@"Is resource reachable: %d", [url          checkResourceIsReachableAndReturnError:&error]);
     NSURLRequest *request = [NSURLRequest requestWithURL:url];
     [webView setScalesPageToFit:YES];
     [webView loadRequest:request];

     [self.view addSubview:webView];
     //[self.view insertSubview:webView atIndex:3];
}
4

1 回答 1

0

您可以在ViewDidLoad.

- (void)viewDidLoad
{
    [super viewDidLoad];



    NSString* pdfFileName = [self getPDFFileName];

 NSMutableDictionary *dataDict = [NSMutableDictionary new];
     NSNumber *tripId = (NSNumber *)[Helper getValueForKeyFromGlobalDictionary:TRIP_ID];
     [dataDict setValue:[self retrieveTimings:[tripId intValue]] forKey:NEWTRIP_MO];
     [dataDict setValue:[self retrieveStops:[tripId intValue]] forKey:TIME_MO];
     [dataDict setValue:[self getCompanyInfo:[tripId intValue]] forKey:COMPANY_MO];
     [dataDict setValue:[self getTripInfo:[tripId intValue]] forKey:TRIP_MO];
     [dataDict setValue:[self getDriverInfo:[tripId intValue]] forKey:DRIVERS_MO];
     [dataDict setValue:[self getLoadInfo:[tripId intValue]] forKey:LOAD_MO];
     [PDFRenderer drawPDF:pdfFileName withData:dataDict];

    UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 40, 320, 440)];

    NSURL *url = [NSURL fileURLWithPath:pdfFileName];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView setScalesPageToFit:YES];
    [webView loadRequest:request];



    [self.view addSubview:webView];

    self.navigationController.navigationBarHidden=NO;
    // Do any additional setup after loading the view from its nib.
}

它为我工作。希望能帮助到你

于 2013-01-26T05:11:59.213 回答