Hoping this takes you out of your misery...
The QuartzPDFView class in QuartzImages.m is not actually instantiated in the viewDidLoad of MainViewController. There, it's class identity is only stored in a dictionary/array referenced by the table view that provides the menu.
The actual quartz view objects are kept in QuartzViewController which itself is created in the didSelectRowAtIndexPath method in MainViewController.
When the QuartzViewController is created and pushed onto the navigation controller, the QuartzViewController's viewDidLoad fires which adds self.quartzView as a subview. The getter method for quartzView (above the viewDidLoad of QVC) finally creates the quartz view object.
So to tell the quartz view to load a given page, here's one way to do it (may not be the most elegant):
- Add a pageNumber property to the QuartzPDFView class
- Set this property in the didSelectRowAtIndexPath method in MainViewController
The minor problem is that the quartzView property in QuartzViewController can be different kinds of quartz views (not just QuartzPDFView). So you need to check that it is a QuartzPDFView before trying to set the pageNumber property.
Step 1: Add pageNumber property to QuartzPDFView class:
//QuartzImages.h
@interface QuartzPDFView : QuartzView
{
CGPDFDocumentRef pdf;
int pageNumber;
}
@property (nonatomic, assign) int pageNumber;
-(void)drawInContext:(CGContextRef)context;
@end
//QuartzImages.m
@implementation QuartzPDFView
@synthesize pageNumber;
...
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber);
...
Step 2: Set this property in the didSelectRowAtIndexPath method in MainViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
QuartzViewController *targetViewController = [self controllerAtIndexPath:indexPath];
if ([targetViewController.quartzView isKindOfClass:[QuartzPDFView class]])
{
((QuartzPDFView *)targetViewController.quartzView).pageNumber = 1;
//replace 1 with whatever number or variable you want
}
[[self navigationController] pushViewController:targetViewController animated:YES];
}
The pdf in the sample app doesn't seem to have more than one page by the way.