xcode IBDesignable视图导致无休止的重建
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29260077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IBDesignable view causes endless rebuilding
提问by BradB
I'm writing a UIView subclass that uses both IBInspectable and IBDesignable. I'm not doing anything unusual, but my subclass causes Xcode 6.2 to endlessly rebuild the project. My Identity Inspector shows this state oscillation under the heading 'Designables':
我正在编写一个同时使用 IBInspectable 和 IBDesignable 的 UIView 子类。我没有做任何不寻常的事情,但我的子类导致 Xcode 6.2 无休止地重建项目。My Identity Inspector 在“Designables”标题下显示了这种状态振荡:
Every time the build restarts, the inspector loses focus. This makes it hard to edit anything from IB, which defeats the purpose of writing this class in the first place.
每次构建重新启动时,检查器都会失去焦点。这使得很难从 IB 中编辑任何内容,这首先违背了编写此类的目的。
Here is the implementation of my DesignableTestView:
这是我的 DesignableTestView 的实现:
import UIKit
@IBDesignable class DesignableTestView: UIView {
@IBInspectable var testBackground:UIColor? {
didSet {
if testBackground != nil {
self.backgroundColor = testBackground
}
}
}
}
Is there any way to change my code or settings of Xcode to prevent the constant rebuilding?
有什么方法可以更改我的代码或 Xcode 设置以防止不断重建?
采纳答案by Rob
I'm wonder if this designable view class is part of the current target. In WWDC 2014 video What's New in Interface Builder, in the Live Views demonstration, they describe that the first step is to ensure that the designable class is in a separate custom framework target. That video demonstrates the process for creating this custom framework target within the project.
我想知道这个可设计的视图类是否是当前目标的一部分。在 WWDC 2014 视频Interface Builder 中的新增功能的 Live Views 演示中,他们描述了第一步是确保可设计类位于单独的自定义框架目标中。该视频演示了在项目中创建此自定义框架目标的过程。
If that's not issue. I'd suggest cleaning your project ("Clean" on "Product" menu) and rebuilding just the custom framework target to make sure that's ok before you try doing anything in IB, itself. Bottom line, make sure that the framework can be built without incident. If the problem still persists after doing that, I'd take it to the next level and (a) find the Xcode derived data folder; (b) quit Xcode; (c) clear the derived data folder, (d) restart Xcode, and (e) trying building the framework target again.
如果那不是问题。我建议清理您的项目(“产品”菜单上的“清理”)并仅重建自定义框架目标,以确保在您尝试在 IB 本身中执行任何操作之前没有问题。最重要的是,确保框架可以顺利构建。如果这样做后问题仍然存在,我会将其提升到一个新的水平,并且 (a) 找到 Xcode 派生数据文件夹;(b) 退出 Xcode;(c) 清除派生数据文件夹,(d) 重新启动 Xcode,以及 (e) 再次尝试构建框架目标。
回答by M. Daigle
I was still having this issue (in Xcode 8.3.3) even after moving my IBDesignable classes into a separate framework. What worked for me was to open the offending Xib file, uncheck Editor > Automatically Refresh Views, and then restart Xcode.
即使将我的 IBDesignable 类移动到单独的框架中,我仍然遇到这个问题(在 Xcode 8.3.3 中)。对我有用的是打开有问题的 Xib 文件,取消选中Editor > Automatically Refresh Views,然后重新启动 Xcode。
回答by Josh
I was ALSO still having this issue Xcode 9.3 even after moving all IBDesignables and IBInspectables to a separate framework (and clean all, kill derived data). IB would continue to rebuild the main target and its dependencies.
即使在将所有 IBDesignables 和 IBInspectables 移动到一个单独的框架(并清理所有,杀死派生数据)之后,我仍然有这个问题 Xcode 9.3。IB 将继续重建主要目标及其依赖项。
The solution I found here https://www.e-learn.cn/content/wangluowenzhang/307740solved it:
我在这里找到的解决方案https://www.e-learn.cn/content/wangluowenzhang/307740解决了:
- remove all
@IBDesignable
and@IBInspectable
- clean all, clear derived data, close Xcode
- reopen Xcode, force IB to rebuild with no IBDesignables (Editor -> RefreshAllViews should be greyed out not)
- close Xcode
- add all
@IBDesignable
and@IBInspectable
back - reopen Xcode
- RefreshAllViews should be available, click it.
- voila, IB never only rebuilds framework from now on
- 删除所有
@IBDesignable
和@IBInspectable
- 清除所有,清除派生数据,关闭 Xcode
- 重新打开 Xcode,强制 IB 在没有 IBDesignables 的情况下重建(Editor -> RefreshAllViews 不应该变灰)
- 关闭 Xcode
- 添加所有
@IBDesignable
并@IBInspectable
返回 - 重新打开Xcode
- RefreshAllViews 应该可用,单击它。
- 瞧,IB 从现在开始不再只重建框架
Clearly there was something funky cached in Xcode that cleanall/killing derived data didn't wipe.
很明显,Xcode 中缓存了一些奇怪的东西,cleanall/killing 派生数据没有擦除。