2012-09-24 51 views
1

我有一個UIViewController在MonoTouch中,作爲一個iPad視圖控制器與一個.xib一起定義。MonoTouch UIViewController與動態類型

如果我改變的UIViewController使用動態類型是這樣的:

public partial class CustomCount : UIViewController<tUnit> where tUnit : struct 
    { 

     private tUnit someVariable; 
    ... (rest of class goes here) ... 

然後MonoTouch的似乎不再生成相應的.h和.m文件,在它的這個視圖控制器Xcode項目。

正因爲如此,我不再能夠訪問任何UI出口(因爲它們是在.m文件中定義)

如果我刪除tTUnit動態類型,一切工作正常。

where tUnit : struct部分對MonoTouch沒有影響。

是否有任何已知的解決方案,或者我應該爲我所期望的每種類型創建我的課的單獨版本?

回答

2

是否需要struct?否則,您可以使用接口。

你能做到這一點,而不是:

public partial class CustomCount : UIViewController 
{ 
    //Use a static method here 
    public static CustomCount Create(ISomeInterface yourVariable) { return new Customcount() { someVariable = yourVariable }; } 

    //Private Constructor 
    private CustomCount() { } 

    private ISomeInterface someVariable; 
} 

你可以事件只是讓someVariable公共財產或什麼的。

+0

在這種情況下,作爲一個結構是首選,但不是每個人的要求,但這是一個不錯的選擇。 +1 –

+0

如果您擔心性能,使用界面不會對您造成太大傷害。您還可以使結構繼承接口:http://blogs.msdn.com/b/abhinaba/archive/2005/10/05/477238.aspx – jonathanpeppers