UIViewControllerHierarchyInconsistency当显示UIAlertController时出现异常
当我尝试从我的应用程序中显示UIAlertController
时,应用程序终止,并出现异常UIViewControllerHierarchyInconsistency
。UIViewControllerHierarchyInconsistency当显示UIAlertController时出现异常
视图控制器与故事板
创建和(尝试)显示警报这样创建:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *yesButton = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
...
}];
[alert addAction:yesButton];
[self presentViewController:alert animated:YES completion:nil];
然而,在执行过程中我得到这个在输出:
2016-08-25 09:46:07.536 TrackYou [10554:3165715] *** Terminati NG应用程序由于未捕获的异常 'UIViewControllerHierarchyInconsistency',理由是: '子视图控制器:
<
UICompatibilityInputViewController:0x13f5afd80>应该有父视图控制器:<
的ViewController:0x13f549360>,但要求家长为:<
UIInputWindowController:0x140043c00>'
从相同的ViewController
我使用presentViewController
来呈现一个自定义ViewController,它工作正常。
SettingsViewController *controller = [SettingsViewController new];
[self presentViewController:controller animated:YES completion:nil];
任何想法是什么原因造成的问题?
我也坚持这个问题,并找到解决办法是,你应该找到顶部视图控制器,并在顶部视图控制器上显示警报。
查找顶视图控制器:
-(UIViewController *)getTopViewController{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
if (![topController isKindOfClass:[NSNull class]]) {
return topController;
}
并呈现在顶部视图控制器警报:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *yesButton = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
...
}];
[alert addAction:yesButton];
[[self getTopViewController] presentViewController:alert animated:YES completion:nil];
感谢您的回复。不幸的是,它并没有解决我的问题。相同的错误:( – Smorka
可能欺骗http://stackoverflow.com/questions/24029113的/ error-when-adding-input-view-to-textfield-ios-8 .. – vaibhav