Reputation: 369
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.
Upvotes: 0
Views: 1277
Reputation: 11
I had the same issue and for me the reason was that another developer had added the pod "UIImage-PDF" to our project, which also provides a class named PDFView but different interface.
Putting this answer here in case someone else had the same root cause for this issue than me.
Upvotes: 1
Reputation: 369
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.
Upvotes: 4
Reputation: 20088
According to Apple's PDFView documentation, there's a document
property that holds the PDF document. Instead of calling setDocument
, set the document
property to your pdfDocument
variable.
Upvotes: 1