UIAlertController 没有显示在模态 UIViewController 上?

UIAlertController not showing on a modal UIViewController?

在 viewcontroller(A) 中,另一个 viewcontroller(B) 将显示为模态 VC。

设置以下属性存在 VC(B) 并将其呈现给密钥 window 中的 topViewController 无效。

B.providesPresentationContextTransitionStyle = YES;
B.definesPresentationContext = YES;
[B setModalPresentationStyle:UIModalPresentationOverCurrentContext];



- (void)presentViewControllerInKeyWindow:(UIViewController*)viewController animated:(BOOL)animated completion:(void (^)(void))completion
{

    UIViewController *topViewController = [UIApplication sharedApplication].keyWindow.rootViewController;

    if(topViewController.presentedViewController != nil) {

        topViewController = [UIApplication sharedApplication].keyWindow.rootViewController.presentedViewController;
        while(topViewController.presentedViewController) {
            topViewController = topViewController.presentedViewController;
        }

    }

    [topViewController presentViewController:viewController animated:animated completion:completion];
}

没有显示警报控制器而是抛出错误。错误说 VC 已经出现。

检查您是否有任何 属性 命名的 inputView 或 inputAccessoryView。如果是,则更改这些名称并尝试。