我尝试使用'developer.apple.com'中的ZoomingPDFViewer源代码并显示PDF文件。我的代码的不同之处在于我正在使用Nib文件来添加一些额外的功能。我只是使用源代码中的PDFScrollView和TiledPDFView类文件。当我尝试调用方法[(PDFScrollView *)self.view setPDFPage:PDFPage];我收到以下错误:
Smart_Reader [408:f803] - [UIView setPDFPage:]:无法识别的选择器 发送到实例0x6ea09b0 Smart_Reader [408:f803] * * 终止 应用程序由于未捕获的异常 *' NSInvalidArgumentException ', 原因:' - [UIView setPDFPage:]:无法识别的选择器发送到实例 0x6ea09b0' *第一次调用堆栈:(0x1283022 0x183bcd6 0x1284cbd 0x11e9ed0 0x11e9cb2 0x2a49 0x489e29 0x489133 0x48a3bf 0x48ca21 0x48c97c 0x4853d7 0x1ea1a2 0x1ea532 0x1d0dc4 0x1c4634 0x2176ef5 0x1257195 0x11bbff2 0x11ba8da 0x11b9d84 0x11b9c9b 0x21757d8 0x217588a 0x1c2626 0x1e5d 0x1dc5)终止调用抛出异常
我对objective-c非常新,这是我在stackoverflow.com上的第一篇文章。我将非常感谢这个伟大社区的任何帮助
PDFReader.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ReaderViewController : UIViewController //<UIScrollViewDelegate>
{
IBOutlet UILabel *TapLabel;
}
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer;
@end
PDFReader.m
#import "ReaderViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "TiledPDFView.h"
#import "PDFScrollView.h"
#import "singleton.h"
@interface ReaderViewController ()
@end
@implementation ReaderViewController
{
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *name = [infoDictionary objectForKey:@"NEWGEN KNOWLEDGE WORKS"];
NSString *version = [infoDictionary objectForKey:@"CFBundleVersion"];
self.title = [NSString stringWithFormat:@"GENIUS READER",name,version];
TapLabel.backgroundColor = [UIColor clearColor];
TapLabel.textColor = [UIColor whiteColor];
TapLabel.textAlignment = UITextAlignmentCenter;
TapLabel.font = [UIFont systemFontOfSize:24.0f];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
singleTap.numberOfTouchesRequired = 1; singleTap.numberOfTapsRequired = 1; //singleTap.delegate = self;
[self.view addGestureRecognizer:singleTap];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
NSInteger Totalpages;
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"fw4" withExtension:@"pdf"];
CGPDFDocumentRef myDocument;
myDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef) pdfURL);// 1
if (myDocument == NULL) {// 2
CFRelease ((__bridge CFURLRef)pdfURL);
}
CFRelease ((__bridge CFURLRef) pdfURL);
Totalpages = CGPDFDocumentGetNumberOfPages(myDocument);
if (Totalpages == 0) {// 5
CGPDFDocumentRelease(myDocument);
}
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(myDocument, 1);
//[c setPDFPage:PDFPage];
//PDFScrollView *PDFview = [[PDFScrollView alloc] init];
//[PDFview setPDFPage:PDFPage];
//[self.view addSubview:[singleton glpData].testsingleton];
[(PDFScrollView *)self.view setPDFPage:PDFPage];
}
@end
答案 0 :(得分:2)
看起来你只是使用了苹果在那个例子中给出的相同代码,
如果您正在使用IBOutlets,请确保已连接IBOutlets
(or)
如果您不使用IB,请确保已在viewDidLoad中启动了PDFScrollView
参考这个答案 - &gt; ZoomingPDFViewer example error