之前都是用我自己手机调试(iOS11)都没什么问题,今天用同事(iOS10.3.1)手机build竟然crash了,看了下crash的地方,进入加载xib的地方。所有这样加载的代码都会crash,奇怪!,xib中没有设置file'sOwner,关联了xib对应的class。
[[NSBundle mainBundle] loadNibNamed: nibName owner: nil options:nil]
完整代码
@implementation ContactInfoDetailView
- (void)awakeFromNib {
[super awakeFromNib];
[_iconLabel addCornerWithRadius: 6.f directions: UIRectCornerAllCorners];
}
+ (ContactInfoDetailView *)getContactInfoView {
NSString *nibName = NSStringFromClass([self class]);
ContactInfoDetailView *view = [[[NSBundle mainBundle] loadNibNamed: nibName owner: nil options:nil] firstObject];
return view;
}
log:
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named _UIColorAttributeTraitStorage'
*** First throw call stack:
libc++abi.dylib: terminating with uncaught exception of type NSException
已知道原因,由于用了ios11的新特效引起的,ios11可以在Asset Catalogs中添加Color,还以为是xcode的新特性可以直接在xib中使用,然而并不能。。。