开发者

How to subclass UIApplication in Monotouch?

EDIT:

A couple of years later, things are easier. It is now possible to omit the Register() attributes, both on the application and the app delegate and instead use:

UIAppli开发者_JAVA百科cation.Main(args, typeof(CustomApp), typeof(CustomAppDelegate));


In order to be able to override UIApplication.SendEvent() I want to subclass UIApplication:

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

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

In the main.cs I use this code:

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

But it fails with:

Objective-C exception thrown.  Name:

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

So I'm missing some attributes I guess. But what and where?


Add a [Register] attribute to your new type, like:

 [Register ("UIApplicationMain")]
 public class UIApplicationMain : UIApplication {
    ...

That will allow the native side to instantiate the right type when Main gets executed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜