PDF viewer question

Discussion in 'iOS Programming' started by alexandergre, Sep 10, 2009.

  1. alexandergre macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #1
    I found a tutorial on the net but cant figure it out.
    In my view based application I have:

    PDFViewController.h
    Code:
    @interface PDFViewController : UIViewController  {
    	UIWebView	*webView;
    	NSURL	*pdfUrl;
    }
    
    @property (nonatomic, retain) IBOutlet UIWebView	*webView;
    @property (nonatomic, retain) NSURL			*pdfUrl;
    
    @end

    PDFViewController.m
    Code:
    #import "PDFViewController.h"
    
    @implementation PDFViewController
    
    @synthesize webView, pdfUrl;
    
    #pragma mark -
    #pragma mark UIViewController methods
    
    - (void)viewDidLoad {
    	[super viewDidLoad];
    	[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
    }
    
    
    @end
    where shall I have this code? in the app delegate?
    :(
    Code:
    // Create an instance of PDFViewController
    PDFViewController *controller = [[PDFViewController alloc] initWithNibName:@"PDFView" bundle:nil];
    // Get the path to our documents directory
    NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    // This should be our documents directory
    NSString *saveDirectory = [documentPath objectAtIndex:0];
    // Our PDF is named 'Example.pdf'
    NSString *saveFileName = @"Example.pdf";
    // Create the full path using our saveDirectory and saveFileName
    NSString *finalPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
    // Set the pdfUrl to our finalPath
    controller.pdfUrl = [NSURL fileURLWithPath:finalPath];
    // Push 'controller'
    [self.navigationController pushViewController:controller animated:YES];
    // Release 'controller'
    [controller release];
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Depends on when you want your PDF view to show up. If right when the app first starts up, then yeah, you can put it in applicationDidFinishLaunching:
     
  3. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #3
    EDIT: Problem REsolved. Apple documentation has some good stuff about PDF.
    Thanx dejo.
     
  4. Aakburns macrumors newbie

    Joined:
    May 22, 2010
    #4
    So where does it actually go?

    I've been working at this for hours now.

    I tried to put it under applicationDidFinishLaunching: but I get one error for this next line.

    [self.navigationController pushViewController:controller animated:YES];

    The error says "Request for memeber 'navigationController' in something not a structure or union"

    Please help.

    Thanks.
     

Share This Page