0

I got this problem from this patch of code:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    /*
     *  get the path to the pdf resource.
     */
    
    NSString *path =
    [[NSBundle mainBundle] pathForResource:@"article"
                                    ofType:@"pdf"];
    NSURL *docURL = [NSURL fileURLWithPath:path];
    
    
    /*
     *  create the Quicklook controller.
     */
    QLPreviewController *qlController = [[QLPreviewController alloc] init];
    
    PreviewItem *item =
    [[PreviewItem alloc] initPreviewURL:docURL
                              WithTitle:@"Article"];
    self.pdfDatasource =
    [[PDFDataSource alloc] initWithPreviewItem:item];
    
    qlController.dataSource = self.pdfDatasource;
    
    
    /*
     *  present the document.
     */
    
    [self presentViewController:qlController
                       animated:YES completion:nil];
}

The line that was causing the problem is the line:

qlController.dataSource = self.pdfDataSource

Also, the iOS app I was trying to make is one that utilizes a QuickLook framework to display a document, if that helps anyone.

I got the code from a guide here. Any help?

P.S. I can't switch to Swift yet for some reasons, so I'll just keep my app as Objective-C for now.

TylerP
  • 9,600
  • 4
  • 39
  • 43
  • I followed the article you linked to -- and it seems to work fine. Are you getting a run-time error? Or are you saying it won't compile because of this line `qlController.dataSource = self.pdfDataSource`? – DonMag Oct 23 '22 at 13:26
  • @DonMag It just straight up errored out when I was editing the code. – Nguyen Thien Minh Oct 24 '22 at 10:42
  • OK - did you follow that complete example? In this question, you only show 1 of the 5 code sections... – DonMag Oct 24 '22 at 12:23
  • Yes, I did, just that I just copied the portion of the code that was causing the error, not the entire thing.... – Nguyen Thien Minh Oct 24 '22 at 14:51
  • Well, difficult to say where your code is wrong if you don't post your code. Try this: create a brand new project... add "article.pdf" to the bundle... replace the default `ViewController.m` with this: https://pastebin.com/81qwjbqj --- it will show the preview controller on tap, instead of in `viewDidAppear` – DonMag Oct 24 '22 at 16:14

0 Answers0