首页 > 解决方案 > 当 UIAlertController 显示时 inputAccessoryView 被关闭

问题描述

对于 iOS 应用程序,我有一个带有 UITextView 的 UIViewController,它使用 inputAccessoryView 将视图保持在屏幕底部(或键盘顶部)。

但是,当我显示 UIAlertController 时,inputAccessoryView 消失了。

 UIAlertController * view =[[UIAlertController alloc]init];
 <Add menuItems>
 [self presentViewController:view animated:YES completion:nil]; <-- inputAccessoryView disappears

我找到了一些解释如何解决此问题的 stackOverFlow文章,但它们不仅在 Swift 中,而且甚至在 Objective-C 中翻译,它也不起作用:

UIViewController *objViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
[objViewController presentViewController:view animated:YES completion:nil];

如何保持我的输入 AccessoryView 显示?

标签: iosobjective-cuiviewcontrollerinputaccessoryview

解决方案


通过正确翻译引用文章中指示的 Swift 答案找到它:

UIViewController *objViewController = [UIApplication sharedApplication].windows.lastObject.rootViewController;
[objViewController presentViewController:view animated:YES completion:nil];

推荐阅读