【问题标题】:MonoTouch UIViewController with dynamic type动态类型的 MonoTouch UIViewController
【发布时间】:2012-09-16 05:01:44
【问题描述】:

我在 MonoTouch 中有一个 UIViewController,与 .xib 一起定义为 iPad 视图控制器。

如果我将 UIViewController 更改为使用这样的动态类型:

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

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

然后 monoTouch 似乎不再在它的 xCode 项目中为此视图控制器生成相应的 .h 和 .m 文件。

因此,我无法再访问任何 UI 插座(因为它们在 .m 文件中定义)

如果我删除 tTUnit 动态类型,一切正常。

where tUnit : struct 部分对 MonoTouch 没有影响。

是否有任何已知的解决方案,或者我应该为我期望的每种类型创建我的班级的单独版本?

【问题讨论】:

    标签: c# uiviewcontroller xamarin.ios monodevelop dynamictype


    【解决方案1】:

    需要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 设为公共财产或其他东西。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2020-07-29
    • 2013-06-20
    相关资源
    最近更新 更多