2015-09-23 27 views
0

我正在使用第三方庫,其結構如下。如何在不在objective-c中引用的情況下調用委託?

@protocol ZipArchiveDelegate; 

@interface Main: NSObject 

//All static methods are declared here 
+ (BOOL)unzipFileAtPath:(NSString *)path 
      toDestination:(NSString *)destination 
       delegate:(id<ZipArchiveDelegate>) delegate; 


//There is no reference of this delegate, while it is calling delegate methods in .m class 
@end 



@protocol ZipArchiveDelegate <NSObject> 
@optional 

- (void)someWorkEnded; 

@end 

現在,當我需要調用此方法時,我在UIViewController Subcalss中調用它。正如我通過委託作爲自我,它給警告說:「Incompitible指針類型發送類id<ZipArchiveDelegate>類型的參數」

[Main unzipFileAtPath:zipLocalPath toDestination:toDestination delegate:self]; 

我怎麼能調用它,因爲沒有靜態方法,所以我用「主」 ,調用方法的類名稱。

謝謝。

+2

你是否聲明你的子類符合ZipArchiveDelegate協議?它應該是這樣的 - YourViewController:UIViewController kirander

+0

如果你有一個應該對消息作出響應的委託,添加一個引用。否則爲零...確保您作爲參考添加的委託對應於非可選委託消息。 – Volker

+0

@kirander,是我已經完成了但問題是別的。 –

回答

1

你是在自己的類方法,這就是爲什麼它不會工作。當在+裏面聲明的方法self指向te類不是一個實例。該方法調用需要一個符合ZipArchiveDelegate的實例。

相關問題