问题描述
在iPhone上的Xcode中,我可以使用这样的代码显示一个弹出视图,该视图覆盖包括Tab栏等在内的所有内容-
On iPhone, in Xcode, I can show a popup view which overlays everything, including the Tab Bar, etc, by using code like this -
[[[[UIApplication sharedApplication] delegate] window] addSubview:mySpecialView];
我正在尝试在MonoTouch中执行相同的操作,而我正在使用的代码是这样-
I'm trying to do the same in MonoTouch, and the code I'm using is this -
UIApplication.SharedApplication.Delegate.Window.AddSubview(mySpecialView);
...但这会崩溃.有人知道我在做什么错吗?
...but this crashes. Does anyone have any idea what I'm doing wrong?
感谢您的帮助.
推荐答案
您没有说明它是如何崩溃的-但是我认为您在使用Window
属性时正在使用ModelNotImplementedException
,因为默认情况下未实现(并且用于情节提要).
You did not say how it crashed - but I assume you're having a ModelNotImplementedException
while using the Window
property since it's not implemented by default (and is meant for storyboard).
您可以实现它以返回(自动生成的)AppDelegate
(AppDelegate.cs文件)的window
字段,也可以公开与(静态)字段相同的变量.
You can either implement it to return the window
field of the (autogenerated) AppDelegate
(AppDelegate.cs file) or expose the same variable as a (static) field.
例如默认生成的代码
UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
window.RootViewController = new UINavigationController ();
window.MakeKeyAndVisible ();
return true;
}
将成为:
static UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
window.RootViewController = new UINavigationController ();
window.MakeKeyAndVisible ();
return true;
}
static public UIWindow Window {
get { return window; }
}
这篇关于Monotouch-弹出式窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!