简体   繁体   English

是否需要从顶视图控制器显示警报视图?

[英]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.

相关问题 如何获取显示的视图控制器的顶视图 - How do I get the top view which is a presented view controller 在所有视图上方添加显示的视图控制器 - Adding presented view controller above all views 了解视图控制器上显示的所有视图 - Know all the views presented on a view controller 如何从显示的视图控制器中打开UIImagePickerController? - How do I open a UIImagePickerController from a presented view controller? 如何防止在出现警报时显示视图控制器的 inputAccessoryView? - How to prevent inputAccessoryView of a view controller from being shown when an alert is presented? 在iOS中从提供的视图控制器推送视图 - Push View from Presented View Controller in iOS 当本地显示视图控制器并显示警报时,控件不会变暗 - Controls not dimming when view controller is presented locally and alert displayed API 调用成功完成 SWIFT 后不显示警报视图控制器 - Alert view controller not presented once API call successfully completed SWIFT iMessage应用程序提供的视图控制器被iMessage顶部栏覆盖,与父项不同 - View Controller presented from iMessage Application gets covered by iMessage top bar unlike the parent 从呈现的视图控制器访问extensionContext - Accessing extensionContext from a presented view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM