c# – 如何在Monotouch中继承UIApplication?

编辑:

几年后,事情变得更容易了.现在可以省略
Register()属性,在应用程序和应用程序委托上,而是使用:

UIApplication.Main(args,typeof(CustomApp),typeof(CustomAppDelegate));

为了能够覆盖UIApplication.SendEvent(),我想要子类化UIApplication:

public class UIApplicationMain : UIApplication
{
    public UIApplicationMain () : base()
    {
    }

    public override void SendEvent (UIEvent uievent)
    {
        base.SendEvent (uievent);
    }
}

在main.cs中我使用以下代码:

public class Application
{
    static void Main (string[] args)
    {
        UIApplication.Main (args,"UIApplicationMain","AppDelegateBase");
    }
}

但它失败了:

06002

NSInternalInconsistencyException Reason: Unable to instantiate the
UIApplication subclass instance. No class named UIApplicationMain is
loaded.

所以我猜错了一些属性.但是在哪里和哪里?

解决方法

将[Register]属性添加到新类型,例如:
[Register ("UIApplicationMain")]
 public class UIApplicationMain : UIApplication {
    ...

这将允许本机端在Main执行时实例化正确的类型.

相关文章

1:最直白的循环遍历方法,可以分为遍历key--value键值对以及...
private void ClearTextBox(){ foreach (var control in pnl...
原文叫看《墨攻》理解IOC概念 2006年多部贺岁大片以让人应接...
右击文件夹->安全选项卡->添加->高级-...