显示UIAlertController时关闭inputAccessoryView

时间:2018-09-23 14:59:07

标签: ios objective-c uiviewcontroller inputaccessoryview

对于iOS应用,我有一个UIViewController和一个UITextView,该UITextView使用inputAccessoryView使视图停靠在屏幕底部(或键盘顶部)。

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

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

我发现一些stackOverFlow articles解释了如何解决此问题,但不仅它们在Swift中,而且甚至在Objective-C中也翻译不了:

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

如何使输入的AccessoryView保持显示状态?

1 个答案:

答案 0 :(得分:0)

通过正确翻译参考文章中指示的Swift答案找到了它:

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