IB Designables: Failed to update auto layout status: The agent raised a "NSInternalInconsistencyException" exception: Could not load NIB in bundle
Asked Answered
P

0

8

I use stroyboard create preview from xib, But I got these error:

file:///Users/miaios/Desktop/Demo/XibDemo/XibDemo/Base.lproj/Main.storyboard: error: IB Designables: Failed to update auto layout status: The agent raised a "NSInternalInconsistencyException" exception: Could not load NIB in bundle: 'NSBundle </Users/miaios/Library/Developer/Xcode/DerivedData/XibDemo-hkqfrktawlqpokczkfobsrmkfxqy/Build/Intermediates/IBDesignables/Products/Debug-iphonesimulator/XibDemo.app> (loaded)' with name 'HXXibView'

file:///Users/miaios/Desktop/Demo/XibDemo/XibDemo/Base.lproj/Main.storyboard: error: IB Designables: Failed to render instance of HXXibView: The agent threw an exception.

Code:

#import <UIKit/UIKit.h>

IB_DESIGNABLE

@interface HXXibView : UIView

@property (nonnull, nonatomic, strong) IBInspectable NSString *text;
@property (weak, nonatomic) IBOutlet UILabel *label;

@end

@implementation HXXibView

#pragma mark - Init Methods
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self xibSetup];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self xibSetup];
    }
    return self;
}

- (void)setText:(NSString *)text {
    _label.text = text;
}
- (NSString *)text {
    return _label.text;
}


#pragma mark - Private Methods
- (void)xibSetup {
    UIView *view = [self loadViewFromNib];
    view.frame = self.bounds;
    [self addSubview:view];
}

- (UIView *)loadViewFromNib {
    NSBundle *bundle = [NSBundle bundleForClass:[HXXibView class]];
    UINib *nib = [UINib nibWithNibName:NSStringFromClass([HXXibView class]) bundle:bundle];
    UIView *view = [[nib instantiateWithOwner:self options:nil] firstObject];
    return view;
}

@end

Xib load by File's Owner Class, not UIView Class, On iOS8 is normal, iOS7 is error

Error path:

1.Change project target to iOS7.

2.Quit Xcode.

3.Clean DerivedData folder.

4.Open project.

5.Selected Main.storyboard, and see preview.

This is Demo

Paregoric answered 17/11, 2015 at 8:48 Comment(1)
Try making it not @IBDesignable for now. That's what I had to do to get this error to go away for this project.Drawn

© 2022 - 2024 — McMap. All rights reserved.