2013-02-12 51 views
0

我正在使用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這些解決方案。

回答

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

0

你的類必須符合UIDocumentInteractionControllerDelegate協議,所以在你.h文件中使它看起來像

@interface ReaderViewController : PerantClass <UIDocumentInteractionControllerDelegate> 
{ 

... 

} 

編譯器會知道你的類遵循該協議。當然,你仍然需要實現所需的方法。

還要檢查這個Link - 1Link - 2.