遗留的区别UIAlertView
和新 UIAlertController
是后者需要通过 presentViewController:animated:completion:
呈现到特定的 View Controller 上。 .这给我的用例带来了一个尴尬的问题:如果已经有 UIAlertController
怎么办?当第二个 View Controller 出现时显示(例如评级对话框)(例如由于网络连接失败而导致的错误对话框)。在这种情况下,我经历过第二个 UIAlertController
只是不显示。
编辑:目前我尝试显示警报,我不知道当前是否有任何显示。
你如何应对这种情况?
最佳答案
我找到了一种解决方法来找出我可以在哪个 View Controller 上显示警报。我也贴了答案here :
@implementation UIViewController (visibleViewController)
- (UIViewController *)my_visibleViewController {
if ([self isKindOfClass:[UINavigationController class]]) {
// do not use method visibleViewController as the presentedViewController could beingDismissed
return [[(UINavigationController *)self topViewController] my_visibleViewController];
}
if ([self isKindOfClass:[UITabBarController class]]) {
return [[(UITabBarController *)self selectedViewController] my_visibleViewController];
}
if (self.presentedViewController == nil || self.presentedViewController.isBeingDismissed) {
return self;
}
return [self.presentedViewController my_visibleViewController];
}
@end
// To show a UIAlertController, present on the following viewcontroller:
UIViewController *visibleViewController = [[UIApplication sharedApplication].delegate.window.rootViewController my_visibleViewController];
关于ios8 - 如果已经显示警报,则显示 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26419458/