0

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?

Pancakes
  • 149
  • 2
  • 7
  • These 2 viewcontrollers are linked in a navigation controller? Have you tried to reinstantiate PdfViewerController in _tableViewSelectionDidChange:_ ? – dmerlea Sep 18 '14 at 06:08
  • No, they're not linked in a navigation controller. Do they need to be? At the moment I'm just trying to get interaction between the two working. I just tried reinstantiating it, still no luck. – Pancakes Sep 18 '14 at 06:13
  • I'm still trying to figure it out what are you doing there. You presented PdfViewerController modally? What happens when you call this line _[pdfViewerController loadFromPath: selectedPath];_ ? – dmerlea Sep 18 '14 at 06:24
  • Absolutely nothing happens when I call that line. I want it to send selectedPath to the loadFromPath method, which subsequently loads that path into my PDFView. I can load a PDF into the PDFView from the init method of the PDFViewController class but when I do it from an instance nothing seems to happen. – Pancakes Sep 18 '14 at 07:18

1 Answers1

0

You are not presenting the pdfViewerController

//Instantiate pdfViewerController from xib / storyboard
PdfViewerController *pdfViewerController = [[PdfViewerController alloc] initWithNibName:@"PdfViewerController" bundle:nil];
//Present it modally
[self presentViewController:pdfViewerController  animated:YES completion:nil];

If you use storyboards: Use this url

Hope should do the thing!

Community
  • 1
  • 1
dmerlea
  • 894
  • 4
  • 12
  • Sorry, I don't know why I tagged this under IOS because I'm not on IOS. I've removed the tag. I assume this advice applies for IOS? Because I have no idea what a storyboard is... – Pancakes Sep 18 '14 at 07:17