Reputation: 2816
I have a UIWindow
nested above all of my navigation controllers (it's a swipeable, draggable mini video player). I'm initializing it like this:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
let player = CustomWindowClass(frame:UIScreen.mainScreen().bounds)
var window: UIWindow? {
set {
}
get {
return player
}
}
}
Now that player
has a button on it's page that should prompt a UIAlertController
. My problem is that I can't presentViewController:
directly from the UIWindow
. I can use:
let rootView = UIApplication.sharedApplication().keyWindow?.rootViewController
rootView?.presentViewController(theAlertController, animated: true, completion: nil)
..but it appears behind my UIWindow
. I've been searching all day for how I can safely display the UIAlertController
above my UIWindow
, but have been empty-handed. Any suggestions?
Upvotes: 1
Views: 2239
Reputation: 12842
What's the size of the returned array of windows
from UIApplication.sharedApplication().windows
?
I'm guessing that it will be 2, and the second one in the array will be your new window. Try investigating each window
in the returned array, and try presenting the UIAlertViewController
on each of those to see if it has the desired effect.
eg, if there are two windows
returned:
let controller = application.windows[1].rootViewController as UIViewController
controller.presentViewController(theAlertController, animated: true, completion: nil)
Reference: How to present UIAlertView from appDelegate
Upvotes: 1