1

我尝试使用来自“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:]: 无法识别的选择器sent to instance 0x6ea09b0' * First throw call stack: (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) terminate called throwing an exception

我对 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
4

1 回答 1

2

似乎您只是使用苹果在该示例中给出的相同代码,

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

(or)

如果您不使用 IB,请确保您已在 viewDidLoad 中启动 PDFScrollView

请参阅此答案-> ZoomingPDFViewer 示例错误

于 2012-07-11T06:34:07.933 回答