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;
}
Written by François Benaiteau
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#