0

I've created a NSWindow with a PDFView in xib file, I created a controller called MainController, there, I created a ibaction -(IBAction) openFileAction:(id) sender, it uses the method

-(void) openFile:(NSString *) path{
  NSLog(@"Opening File %@",path);
  PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]];
  [pdfView setDocument: pdfDoc]; 
}

I linked the open menu item to openFileAction and pdf file is shown properly in PDFView after the click.

I'm doing a logic to receive a command line argument

-(MainController *) init{
  [super init];
  NSArray *myArgs = [[NSProcessInfo processInfo] arguments];
  NSLog(@"pdf view %@", pdfView);
  if ([myArgs count] >= 2 ){ 
    [self openFile:[myArgs objectAtIndex:1]];
  }

  return self;
}

As you can see, I did an override in default constructor and in this context the pdfView is null then the file is not opened after the application/main Window load.

My question is, how can I open a pdf in a PDFView after the application load? Is there any hook to use after UI load?

Shairon Toledo
  • 2,024
  • 16
  • 18

2 Answers2

0

If you want to do this when your window opens that your PDFView is in, use the windowDidLoad function in your MainController rather than trying to load it in init.

slycrel
  • 4,275
  • 2
  • 30
  • 30
0

Thanks slycrel but windowDidLoad is a callback of NSWindowController. I found the solution by myself, the secret is

- (void) awakeFromNib{
 //Do something after initialize UI components 
}

All the best.

Shairon Toledo
  • 2,024
  • 16
  • 18