Monotouch - Popups over everything

2019-06-07 05:30发布

问题:

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