Reputation: 7444
My PDF scroll view (copied from Apple’s ZoomingPDFViewer example, but modified a bit) can’t seem to zoom, although it’s displaying the data.
Here is what Apple uses in the example to add it:
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
[(PDFScrollView *)self.view setPDFPage:PDFPage];
And because that second line gave me errors, I changed it to this:
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
PDFScrollView *sv = [[PDFScrollView alloc] initWithFrame:self.view.frame];
[sv setPDFPage:PDFPage];
self.view = sv;
But now I can’t seem to zoom the PDF.
The Apple one works well without errors, but if I use this line in my app, I get the following error when that view loads:
-[UIView setPDFPage:]: unrecognized selector sent to instance 0x1c5b10b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setPDFPage:]: unrecognized selector sent to instance 0x1c5b10b0'
*** First throw call stack:
(0x3424c2a3 0x33a1e97f 0x3424fe07 0x3424e531 0x341a5f68 0x8c499 0x36da3595 0x36df813b 0x36df8081 0x36df7f65 0x36df7e89 0x36df75c9 0x36df74b1 0x36de5b93 0x36de5833 0x79acd 0x36e46275 0x36ec8ea9 0x39249a6f 0x342215df 0x34221291 0x3421ff01 0x34192ebd 0x34192d49 0x34efb2eb 0x36dd8301 0x6e601 0x38e17b20)
libc++abi.dylib: terminate called throwing an exception
The only other difference in my setup is that the view controller where this is called is inside a navigation controller, which is inside of a tab bar controller. But I can’t see how this would affect the problem.
Any tips?
This is my custom init method:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.decelerationRate = UIScrollViewDecelerationRateFast;
self.delegate = self;
self.scrollEnabled = true;
}
return self;
}
It is the same as initWithCoder
except that I added self.scrollEnabled = true;
.
I also tried these, and it still didn’t work:
//UIScrollView *sv = [[UIScrollView alloc] initWithFrame:self.view.frame];
PDFScrollView *sv = [[PDFScrollView alloc] initWithFrame:self.view.frame];
self.view = sv;
[(PDFScrollView *)self.view setPDFPage:PDFPage];
When I use the commented-out line (UIScrollView), it gives me the same error, except that it says [UIScrollView setPDFPage:]: unrecognized...
. When I use the uncommented line (PDFScrollView), it gives me no error and shows the PDF, but there’s still no zooming.
Upvotes: 1
Views: 731
Reputation: 13267
self.view
must be a scroll view in order to be cast as a PDFScrollView
and accept its methods. By default, self.view
is a UIView. Either change the view to a scroll view in your XIB file (delete the view and link the scroll view to view
in File's Owner) or do it programmatically.
Upvotes: 2