简体   繁体   English

自动版式:NSInternalInconsistencyException与iOS11

[英]AutoLayout: NSInternalInconsistencyException with iOS11

App getting crashed with the following logs(PFA) and Its only getting crash in iOS 11. 应用程序崩溃并显示以下日志(PFA),并且它仅在iOS 11中崩溃。

Fatal Exception: NSInternalInconsistencyException, Impossible to set up layout with view hierarchy unprepared for constraint. 致命异常:NSInternalInconsistencyException,无法设置布局而视图层次结构未准备好约束。

__120-[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]_block_invoke_2 __120- [UIView(UIConstraintBasedLayout)_layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] _ block_invoke_2

在此处输入图片说明

Update :- 更新 :-

Scenario:- I have a UIToolbar on the keyboard, The code for adding 场景:-我在键盘上有一个UIToolbar,用于添加的代码

The view hierarchy is not prepared for the constraint: NSLayoutConstraint:0x1c0295540 V:[UIToolbar:0x10219f550]-(0)-[_UIRemoteKeyboardPlaceholderV‌​iew:0x10219fab0] (inactive) 没有为约束准备视图层次结构:NSLayoutConstraint:0x1c0295540 V:[UIToolbar:0x10219f550]-(0)-[_ UIRemoteKeyboardPlaceholderV‌iew:0x10219fab0](无效)

#pragma mark  KeyBoard Related Function
-(void)createInputAccessoryView:(NSInteger )tagNumber
{
    inputAccessoryView = [[UIToolbar alloc]init];
    [inputAccessoryView setBackgroundColor:kKYBOARDCOLOR];
    [inputAccessoryView sizeToFit];
    [inputAccessoryView setHidden:NO];

    //Use this to put space in between your toolbox buttons

    UIBarButtonItem *barSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                              target:nil
                                                                              action:nil];

    UIBarButtonItem *barBtnDone = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                   style:UIBarButtonItemStyleDone
                                                                  target:self action:@selector(actnResignKeyboard)];
    NSArray *barItems;
    barItems = [NSArray arrayWithObjects:barSpace,barBtnDone, nil];
    [inputAccessoryView setItems:barItems animated:YES];

}

Appearing and disappearing keyboard causes crash but when I remove UIToolbar, then every thing working fine. 键盘的出现和消失都会导致崩溃,但是当我删除UIToolbar时,一切正常。

Note :- This code is working fine prior to iOS 11. 注意:-此代码在iOS 11之前运行良好。

Did you try printing the stacktrace to know which layout or view hierarchy causes this? 您是否尝试打印stacktrace来了解导致此问题的布局或视图层次结构? Also try adding the views to the superview first and then apply the constraints 也尝试先将视图添加到超级视图,然后应用约束

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM