I am using Xcode 9.4 with Objective C. I want display pdf file using PDFView as per the below code
PDFView * pdfView = [[PDFView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
NSString* path = [[NSBundle mainBundle] pathForResource:@"abc" ofType:@"pdf"];
NSData* data = [NSData dataWithContentsOfFile:path];
PDFDocument *pdfDocument = [[PDFDocument alloc] initWithData:data];
[pdfView setDocument:pdfDocument];
But it fails with SetDocument unrecognised selector instance along with below error.
Error:
-[PDFView setDocument:]: unrecognized selector sent to instance 0x101367c40
error: Execution was interrupted, reason: Attempted to dereference an invalid ObjC Object or send it an unrecognized selector. The process has been returned to the state before expression evaluation.
I am not able to identify the exact problem, please help.
Thank you.
Finally,
I got the solution, Just add UIView in storyboard and set the class as a PDFView in Inspector. And create the IBOutlet object of PDFView and assign it to UIView in storyboard and set the pdfdocument to the PdfView along with properties if required.
Code:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Swift" ofType:@"pdf"]];
PDFDocument *document = [[PDFDocument alloc]initWithURL:url];
_pdfView.document = document;
_pdfView.frame = self.view.frame;
_pdfView.displayDirection = kPDFDisplayDirectionHorizontal;
Thank you all for your valuable efforts for discussion.