如何在 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");
}
}
但它失败了:
抛出 Objective-C 异常。姓名:
NSInternalInconsistencyException 原因:无法实例化 UIApplication 子类实例。没有名为 UIApplicationMain 的类 已加载。
所以我猜我缺少一些属性。但什么以及在哪里?
EDIT:
A couple of years later, things are easier. It is now possible to omit theRegister()
attributes, both on the application and the app delegate and instead use:
UIApplication.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
向您的新类型添加一个 [Register] 属性,例如:
这将允许本机端在执行 Main 时实例化正确的类型。
Add a [Register] attribute to your new type, like:
That will allow the native side to instantiate the right type when Main gets executed.