Embedding a VFR Reader inside another view

677 views Asked by At

I'm trying to add PDF viewing capability to my iPad app using the VFR Reader code.

I can use the existing ReaderViewController to display Reader as a full screen page using code like:

ReaderDocument *document = [ReaderDocument withDocumentFilePath:file password:nil];
if (document != nil)
{
    ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
    // ...
    [self presentModalViewController:readerViewController animated:YES];
}

which works very nicely indeed.

However, I'd like to have other things around the PDF (such as a permanently display bar with buttons on along the top, for example), so ideally I'd like the Reader view inside a view of my own.

I'm rather new to iOS programming and can't figure out how to go about achieving this. Could someone point me in the right direction and tell me what I need to do to have my own view with VFR Reader in a sub-view?

1

There are 1 answers

1
Dave W On BEST ANSWER

I managed to figure out how to do this. Here's the solution for anyone who may be interested.

I created my container ViewController whose xib contained a UIView as a placeholder for the location of the PDF, then in its viewDidLoad method:

// Create the sub-ViewController, the VFR Reader ViewController
ReaderDocument *document = [ReaderDocument withDocumentFilePath:pdfFile password:nil];
_readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];

// Pass on the required delegate for handling the close button
_readerViewController.delegate = self.delegate;

// Add the VFR Reader as a child
[self addChildViewController:_readerViewController];
[self.view addSubview:_readerViewController.view];
// Set the location of the VFR Reader to the same as the placeholder view
_readerViewController.view.frame =  self.pdfPlaceholder.frame; 
[_readerViewController didMoveToParentViewController:self];