58bimg
Last Updated: February 25, 2016
·
4.142K
· netbe
2012 05 26 23.03.46

error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool raised a "NSInternalInconsistencyException" exception: Could not load NIB in bundle: 'NSBundle

While using IBDesignable I got this error:

error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool raised a "NSInternalInconsistencyException" exception: Could not load NIB in bundle: 'NSBundle

Code CustomView.m :

- (instancetype)initWithFrame:(CGRect)frame {
    self = [self.class loadFromXib];
    self.frame = frame;
    return self;
}

+ (instancetype)loadFromXib {
    NSArray* elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
    for (id anObject in elements) {
        if ([anObject isKindOfClass:[self class]]) {
            return anObject;
        }
    }
    return nil;
}

It seemed that effectively the nib was not in the bundle which was used.

Solution using bundleForClass: :

...
+ (instancetype)loadFromXib {
    NSArray* elements = [[NSBundle bundleForClass:self] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
    for (id anObject in elements) {
        if ([anObject isKindOfClass:[self class]]) {
            return anObject;
        }
    }
    return nil;
}
Say Thanks
Respond