简体   繁体   English

在框架内使用类时,IB_DESIGNABLE构建失败

[英]IB_DESIGNABLE build failed when using class from within a framework

I created a new embedded framework. 我创建了一个新的嵌入式框架。 Within the framework I created a class called "WBButton", which is a subclass of UIButton. 在框架内,我创建了一个名为“WBButton”的类,它是UIButton的子类。 I have set the IB_DESIGNABLE and added IBInspectable attributes to allow configuration through Interface builder, as explained here . 我已经设置了IB_DESIGNABLE并添加IBInspectable属性允许配置通过界面生成器,为解释在这里

It works fine when I test it from within my framework (by adding a sample .xib and placing the button on the screen), but when adding the custom button to a nib located on the project which contains the framework, I get a "Build Failed" message next to the "Designables" (see below). 当我在我的框架中测试它时(通过添加示例.xib并将按钮放在屏幕上),它工作正常,但是当将自定义按钮添加到位于包含框架的项目上的nib时,我得到一个“构建” “Designables”旁边的“消息失败”(见下文)。

Also, what does "Module" mean in Interface builder? 另外,“模块”在“界面”构建器中的含义是什么?

在此输入图像描述

Xcode 6 has a bug that breaks IB_DESIGNABLE classes defined in static library or framework. Xcode 6有一个错误,它破坏了静态库或框架中定义的IB_DESIGNABLE类。 The same is with CocoaPods which use static library for all Pods. 对于所有Pod使用静态库的CocoaPods也是如此。

It seems this is an Xcode bug 这似乎是一个Xcode错误

Temporary workaround: 临时解决方法:

Create an empty category/extension in the target that contains the storyboard or nib you want to use the designable view in. 在目标中创建一个空的类别/扩展,其中包含要使用可设计视图的故事板或笔尖。

Swift: 迅速:

extension CustomView {

}

Objective-C: Objective-C的:

//.h
@interface CustomView (Category)

@end

//.m
@implementation CustomView (Category)

@end

@Andy's comment above is correct answer if you use CocoaPods and your custom library is not working, you need to uncomment use_frameworks! @ Andy上面的评论是正确答案如果您使用CocoaPods并且您的自定义库不起作用,您需要取消注释use_frameworks! in your Podfile and "pod install" again. 在您的Podfile和“pod安装”中再次。

Apparently the "IB_DESIGNABLE" is not recognized by XCode if you don't do this. 显然,如果不这样做,XCode就无法识别“IB_DESIGNABLE”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM