Monotouch - Popups over everything

有些话、适合烂在心里 提交于 2020-01-14 04:09:06

问题


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];

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?

Thanks for any help.


回答1:


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).

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.

E.g. the default generated code

UIWindow window;

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    window = new UIWindow (UIScreen.MainScreen.Bounds);
    window.RootViewController = new UINavigationController ();
    window.MakeKeyAndVisible ();
    return true;
}

would become:

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; }
}


来源:https://stackoverflow.com/questions/12372352/monotouch-popups-over-everything

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!