对象C代表不兼容类型

问题描述:

我正在使用http://www.vfr.org/,pdf查看器,并尝试添加一个按钮以在IBOOK中打开PDF。对象C代表不兼容类型

我向它添加了按钮和动作,但是当我想用这个pdf格式打开ibooks应用程序时,我困惑了。

我试过2个解决方案:

  1. 按钮窃听行动:

    NSURL *fileURL = document.fileURL; 
    NSString *fileName = document.fileName; // Document 
    [[UIApplication sharedApplication] openURL:fileURL]; 
    

它打开了IBOOKS但从来没有PDF被加载。

我假设URL格式可以是错误的我试过甚至硬编码PDF网址,如:

NSString *stringURL = @"itms-books://linktopdf.pdf";  
NSURL *url = [NSURL URLWithString:stringURL]; 
[[UIApplication sharedApplication] openURL:url]; 

但相同的结果。

2)按钮窃听行动:

NSURL *fileURL = document.fileURL; 
    NSString *fileName = document.fileName; // Document 
    UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init]; 
    docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; 
    docController.delegate = self; 

但是我有一个警告,我试图委派:docController.delegate = self;

assigning to id UIDocumentInteractionControllerDelegate from Incompatible ReaderViewController

有人可以帮助我,使工作至少1这些解决方案。

已在ReaderViewController这种行在头文件中:@interface ReaderViewController : NSObject <UIDocumentInteractionControllerDelegate>

+0

Larme,我更新的问题 – AlexC 2013-02-12 14:47:50

+0

我在@interface动了我的变数名称,但我认为这是不正确的 – AlexC 2013-02-12 14:48:19

+0

我还没有看到的'UIDocumentInteractionControllerDelegate' * *。它应该是这样的:'@interface ReaderViewController:的UIViewController ' – Larme 2013-02-12 14:58:58

你的类必须符合UIDocumentInteractionControllerDelegate协议,所以在你.h文件中使它看起来像

@interface ReaderViewController : PerantClass <UIDocumentInteractionControllerDelegate> 
{ 

... 

} 

编译器会知道你的类遵循该协议。当然,你仍然需要实现所需的方法。

还要检查这个Link - 1Link - 2.