[英]Do alert views need to be presented from the top view controller?
When presenting an UIAlertController
is it necessary to use the top most UIViewcontroller
on the screen? 当呈现
UIAlertController
是否有必要使用屏幕上最顶部的UIViewcontroller
? Does this UIViewController
need to be visible or just in the view hierarchy? 这个
UIViewController
是否需要可见还是仅在视图层次结构中可见? Would there be any disadvantage if presenting any alert directly from the UIWindow
's root viewController? 如果直接从
UIWindow
的根viewController呈现任何警报,将会有任何不利之处吗?
In my opinion there is nothing wrong in presenting from the root view controller of the application. 在我看来,从应用程序的根视图控制器进行呈现没有任何错误。 Take a look at the following question and the accepted answer How to present UIAlertController when not in a view controller?
看下面的问题和可接受的答案如何在不在视图控制器中时显示UIAlertController?
I've used a category on UIAlertViewController similar to what have been proposed in the answers in the above link, and I've never faced any problem. 我在UIAlertViewController上使用了类似于上述链接中的答案中提出的类别,而且我从未遇到过任何问题。
I think it's better to present the UIAlertViewController
from the currently presented view controller. 我认为最好从当前呈现的视图控制器呈现
UIAlertViewController
。 For me I used to get the currently presented view controller like this: 对我来说,我曾经像这样获得当前呈现的视图控制器:
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UIViewController *viewController = keyWindow.rootViewController;
while (viewController.presentedViewController) {
viewController = viewController.presentedViewController;
}
[viewController presentViewController:alertController animated:YES completion:nil]
Using the root to present the view controller caused an issue for me before but I can't remember actually. 使用根来呈现视图控制器以前对我造成了一个问题,但实际上我不记得了。 You're at the safe side while using the top most one.
使用最顶级的产品时,您处于安全的一面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.