iPhone SDK - 通过UIViewController从AppDelegate显示UIView [英] iPhone SDK - Display a UIView from the AppDelegate over a UIViewController
问题描述
我希望我的标题有意义。
I hope my title makes sense.
我有一个iPhone应用程序使用标准的 UINavigationController
I have an iPhone app uses the standard UINavigationController
approach to push new view controllers and let the user navigate as they wish.
现在,在我的 AppDelegate
中,我有一个方法在定时器上运行,该定时器调用Web服务。如果这个服务返回一个特定的响应,我想能够显示一个 UIView
(本质上是一个自定义警报框,但我不想使用 UIAlertView
class)。
Now, in my AppDelegate
I have a method which runs on a timer, which calls out to a web service. If this service comes back with a particular response, I want to be able to display a UIView
(essentially a custom alert box, but I don't want to use the UIAlertView
class).
如何获得这个UIView(在 AppDelegate )显示在
/ p> UIWindow
上,因此在导航控制器推送的任何和所有视图之上?
How can I get this UIView (defined in the AppDelegate
) to display on the UIWindow
- and therefore on top of any and all views which have been pushed by the navigation controller?
推荐答案
你的AppDelegate应该有一个属性 window
。窗口是一个视图,所以你可以做 [self.window addSubview:newView];
Your AppDelegate is supposed to have a property window
. A window is a view, so you can do [self.window addSubview:newView];
添加到应用程序视图层次结构中的UIViews有一个属性 window
,指向同一个对象。所以一个视图控制器可以到达窗口而不处理应用程序委托。
Note: Also UIViews, that are added to the app's view hierarchy have a property window
, pointing to the same object. So a view controller can reach the window without dealing with the app delegate.
[controller.view.window addSubview:overlayView];
确保这是在您设置 rootViewController
。您也可能需要 [self.window bringSubviewToFront:newView]
Make sure this is after you have set the rootViewController
. Also you might need [self.window bringSubviewToFront: newView]
这篇关于iPhone SDK - 通过UIViewController从AppDelegate显示UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!