I have a document based application. It's supposed to be a PDFViewer where the user picks a PDF from the left table and it's loaded into the PDF view on the right.
In my Document class I create an instance of my WindowController, which is the File Owner of my Document.xib, and make it the window controller like this:
- (id)init
{
self = [super init];
if (self) {
controller = [[WindowController alloc] initWithWindowNibName:@"Document"]; }
return self;
}
-(void)makeWindowControllers {
[self addWindowController: controller];
}
My Window Controller then creates an instance of my TableViewController which controls my NSTableView:
@implementation WindowController
-(id)initWithWindowNibName:(NSString *)window {
self = [super initWithWindowNibName:window];
return self;
}
-(void)windowDidLoad
{
tableViewController = [[TableViewController alloc] init];
}
@end
The TableViewController has a connected outlet to my NSTableView.
The TableViewController then controls the PDFViewer by owning an instance of PDFViewerController, which was alloc'd and init'd in it's init method. PDFViewerController class also has a connected outlet to my PDFView.
The PDFViewerController has this method for loading a PDF:
-(void) loadFromPath: (NSString *) path{
NSLog(@"PDFController trying to load path %@", path);
PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL: [NSURL fileURLWithPath: path]];
[pdfView setDocument: pdfDoc];
}
When the table view selection changes it should tell loadFromPath: from the PDFViewerController instance to load that PDF into the view, like this:
-(void) tableViewSelectionDidChange:(NSNotification *)notification{
// If the user clicks another file in the list we should let everyone know the path
selectedPath = [[list objectAtIndex: [[notification object] selectedRow]] path];
NSLog(@"trying to load path %@", selectedPath);
[pdfViewerController loadFromPath: selectedPath];
}
However my PDFViewer doesn't respond at all. I can't figure out why... I have everything connected. If I tell it to load a PDF in the init method of the PDFViewerController it works fine, same for the TableViewController. It seems I just can't call instance methods? What am I doing wrong here?