2012-05-23 53 views
3

我有一個外部的庫如何映射從MonoTouch中的兩個類派生的接口?

@interface AGSGPS : UIView <CLLocationManagerDelegate> 

通常你會在ApiDefinition.cs定義爲以下接口定義:

[BaseType (typeof (UIView))] 
interface AGSGPS : CLLocationManagerDelegate 

這樣做的問題是,無論UIViewCLLocationManagerDelegate是類和這可以分解爲以下代碼:

class AGSGPS : UIView, CLLocationManagerDelegate 

這是非法的al在C#

想法?

+0

我有一個可能的修復我只是想和我的測試,而不是使用預先定義的CLLocationManagerDelegate,我在ApiDefinition文件中重新定義它,然後能夠從它派生出來,因爲它是一個接口而不是一個類,不是最優的,但總比沒有好。 – Kenny

+0

看看[WeakDelegate](http://tirania.org/blog/archive/2009/Oct-15.html) – holmes

回答

3

您不需要「映射」該對象。尖括號中的類型是協議,這意味着您的AGSGPS對象採用該協議。

檢查文檔here

現在,採用的協議意味着你的對象應該實現所有協議的方法。要在ApiDefinition做到這一點,只是把CLLocationManagerDelegate的方法,就好像它們屬於你AGSGPS類型,例如:

[BaseType (typeof (UIView))] 
interface AGSGPS 
{ 

    [Export("locationManager:didUpdateHeading:")] 
    void UpdatedHeading(CLLocationManager lman, CLHeading heading); 

    // etc, include all CLLocationManagerDelegate's methods 
} 
+0

我基本上做了同樣的事情,重新定義了ApiDefinition中的接口並從中派生出來,仍然在處理儘管如此,所有的API都會看到它是如何工作的。 – Kenny

相關問題