[フレーム]
Last Updated: December 26, 2018
·
6.855K
· netbe

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;
}

AltStyle によって変換されたページ (->オリジナル) /