IB Designables:无法更新自动布局状态:代理引发了“NSInternalInconsistencyException”异常:无法在bundle中加载NIB

时间:2015-11-17 08:48:13

标签: ios objective-c ibdesignable

我使用stroyboard从xib创建预览,但是我收到了这些错误:

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.

代码:

#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加载File's Owner类,而不是UIView类,开iOS8是正常的,iOS7是错误

错误路径:

  

1.将项目目标更改为iOS7

     

2.Quit Xcode。

     

3.Clean DerivedData文件夹。

     

4.打开项目。

     

5.选择Main.storyboard,然后查看预览。

这是Demo

0 个答案:

没有答案