Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用PDFKit for iPad加载pdf_Ios_Objective C - Fatal编程技术网

Ios 如何使用PDFKit for iPad加载pdf

Ios 如何使用PDFKit for iPad加载pdf,ios,objective-c,Ios,Objective C,我有这段代码 LoadPdf(void* currentView,NSData* content,NSString* urlName) { UIView tmpView = (UIView)currentView; NSData *data = content; PDFDocument *pdfDocument = [[PDFDocument alloc] initWithData:data]; PDFView *pdfView = [[PDFView al

我有这段代码

LoadPdf(void* currentView,NSData* content,NSString* urlName) {
    UIView tmpView = (UIView)currentView;

    NSData *data = content;

    PDFDocument *pdfDocument = [[PDFDocument alloc] initWithData:data];

    PDFView *pdfView = [[PDFView alloc] initWithFrame: CGRectMake(0, 0, 1000, 1000)];
    pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
    pdfView.autoScales = NO ;
    pdfView.displayDirection = kPDFDisplayDirectionHorizontal;
    pdfView.displayMode = kPDFDisplaySinglePageContinuous;
    pdfView.displaysRTL = YES ;
    [pdfView setDisplaysPageBreaks:YES];
    [pdfView setDisplayBox:kPDFDisplayBoxTrimBox];
    pdfView.document = pdfDocument;

    [tmpView addSubview:pdfView];
}

但它并没有在视图中加载PDF。此外,如果我使用CGrect,则整个PDF不会显示在调试器中。如何初始化PDFView并加载它?

我发现了一篇非常好的文章,详细介绍了如何使用
PDFView

一些Swift代码。我知道你是在Objective-C中问这个问题的,但既然你喜欢iOS,你应该能够理解上下文

    if let path = Bundle.main.path(forResource: "MFI_2018_01", ofType: "pdf") {
        let url = URL(fileURLWithPath: path)
        if let pdfDocument = PDFDocument(url: url) {
            pdfView.displayMode = .singlePageContinuous
            pdfView.autoScales = true
            // pdfView.displayDirection = .horizontal
            pdfView.document = pdfDocument
        }
    }
高安

使用以下代码在我自己身上进行了测试:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIView *tmpView = [self view];

    NSData *data = [NSData dataWithContentsOfFile: @"local File on disk.pdf"];

    PDFDocument *pdfDocument = [[PDFDocument alloc] initWithData:data];

    PDFView *pdfView = [[PDFView alloc] initWithFrame: CGRectMake(0, 0, 1000, 1000)];
    pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
    pdfView.autoScales = NO ;
    pdfView.displayDirection = kPDFDisplayDirectionHorizontal;
    pdfView.displayMode = kPDFDisplaySinglePageContinuous;
    pdfView.displaysRTL = YES ;
    [pdfView setDisplaysPageBreaks:YES];
    [pdfView setDisplayBox:kPDFDisplayBoxTrimBox];
    pdfView.document = pdfDocument;

    [tmpView addSubview:pdfView];

}
而且它可以毫无问题地显示PDF

我唯一发现的是

UIView tmpView = (UIView)currentView;
您静态分配了tmpview,它应该是

UIView *tmpView = (UIView *)currentView;

否则,请测试您的数据是否为有效的Pdf。

谢谢。我浏览了一下这篇文章,并相应地修改了代码,但是没有用。嗨,艾维昂,谢谢你的回复。我是Objective-C新手。我使用WLanguage(Windev Mobile)构建生成Objective-C代码的iOS应用程序。我使用的语言不支持PDF,因此尝试从WLanguage代码运行Objective-C代码。我在调试时可以看到PDF是正确的,但在某些地方它没有添加到视图中。如果您使用PDF函数,则必须在Xcode中添加“PDFKit.framework”,您可以使用链接的框架添加。我不知道如何使用WLanguage.Correct添加它。我在Xcode中添加了这个。当它不存在时没有编译/生成。可能是与ViewController相关的东西,我在WLanguage中没有看到。您能在代码开头的Xcode中设置断点,并检查tempview是否可能为零。这就是我得到的错误-[CFenPrincipaleViewController addSubview:]:发送到实例0x7fb4884f5900的选择器无法识别。currentView如果我在调试器中打开,请显示我的视图。当我试图在调试器中打开tmpView时,调试器说无法加载tmpView的数据快速查找数据