【问题标题】:iPad PDF file display using apple's ZoomingPDFViewer source codeiPad PDF文件显示使用苹果的ZoomingPDFViewer源码
【发布时间】:2012-07-11 14:34:07
【问题描述】:

我尝试使用来自“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

【问题讨论】:

    标签: ipad pdf pdf-generation


    【解决方案1】:

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

    如果你正在使用,请确保你已经连接了 IB 中的 IBOutlets

    (or)
    

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

    参考这个答案 --> ZoomingPDFViewer example error

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 2011-02-03
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多