Ipad 使用apple';s ZoomingPDFViewer源代码

Ipad 使用apple';s ZoomingPDFViewer源代码,ipad,pdf,pdf-generation,Ipad,Pdf,Pdf Generation,我试图使用“developer.apple.com”的源代码并显示一个PDF文件。我的代码的不同之处在于,我使用了一个Nib文件来添加一些额外的特性。我只是简单地使用源代码中的PDFScrollView和TiledPDFView类文件。当我尝试调用方法[(PDFScrollView*)self.view setPDFPage:PDFPage]时;我得到以下错误: 智能读卡器[408:f803]-[UIView setPDFPage:]:无法识别的选择器 发送到实例0x6ea09b0智能读卡器[4

我试图使用“developer.apple.com”的源代码并显示一个PDF文件。我的代码的不同之处在于,我使用了一个Nib文件来添加一些额外的特性。我只是简单地使用源代码中的PDFScrollView和TiledPDFView类文件。当我尝试调用方法[(PDFScrollView*)self.view setPDFPage:PDFPage]时;我得到以下错误:

智能读卡器[408:f803]-[UIView setPDFPage:]:无法识别的选择器 发送到实例0x6ea09b0智能读卡器[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
#导入
#进口
@接口ReaderViewController:UIViewController//
{
IBUILabel*TapLabel;
}
-(void)handleSingleTap:(UITapGestureRecognitor*)识别器;
@结束
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
#导入“ReaderViewController.h”
#进口
#导入“TiledPDFView.h”
#导入“PDFScrollView.h”
#导入“singleton.h”
@接口ReaderViewController()
@结束
@ReaderViewController的实现
{
}
-(无效)viewDidLoad
{
[超级视图下载];
self.view.backgroundColor=[UIColor clearColor];
NSDictionary*infoDictionary=[[NSBundle mainBundle]infoDictionary];
NSString*name=[infoDictionary objectForKey:@“NEWGEN知识工程”];
NSString*版本=[infoDictionary objectForKey:@“CbundLeverVersion”];
self.title=[NSString stringWithFormat:@“GENIUS READER”,名称,版本];
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.numberoftouchsrequired=1;singleTap.numberOfTapsRequired=1;//singleTap.delegate=self;
[self.view addgesturecognizer:singleTap];
}
-(无效)视图卸载
{
[超级视频下载];
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回YES;
}
-(无效)handleSingleTap:(UITapGestureRecognitor*)识别器
{
NSInteger总页数;
NSURL*pdfURL=[[NSBundle mainBundle]URLForResource:@“fw4”带扩展名:@“pdf”];
CGPDFDocumentRef myDocument;
myDocument=CGPDFDocumentCreateWithURL((_桥CFURLRef)pdfURL);//1
如果(myDocument==NULL){//2
CFRelease((uu桥CFURLRef)pdfURL);
}
CFRelease((uu桥CFURLRef)pdfURL);
Totalpages=CGPDFDocumentGetNumberOfPages(myDocument);
如果(Totalpages==0){//5
CGPDFDocumentRelease(myDocument);
}
cgpdfageref 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];
}
@结束

看起来您使用的代码与苹果在该示例中给出的代码相同

如果正在使用IB,请确保已连接IB中的IBOutlet

(or)
如果未使用IB,请确保已在viewDidLoad中启动PDFScrollView

请参考此答案-->