IBDesignable view causes endless rebuilding

心已入冬 提交于 2019-12-31 19:29:14

问题


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':

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.

Here is the implementation of my 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?


回答1:


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.

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.




回答2:


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.




回答3:


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.

The solution I found here https://www.e-learn.cn/content/wangluowenzhang/307740 solved it:

  1. remove all @IBDesignable and @IBInspectable
  2. clean all, clear derived data, close Xcode
  3. reopen Xcode, force IB to rebuild with no IBDesignables (Editor -> RefreshAllViews should be greyed out not)
  4. close Xcode
  5. add all @IBDesignable and @IBInspectable back
  6. reopen Xcode
  7. RefreshAllViews should be available, click it.
  8. voila, IB never only rebuilds framework from now on

Clearly there was something funky cached in Xcode that cleanall/killing derived data didn't wipe.



来源:https://stackoverflow.com/questions/29260077/ibdesignable-view-causes-endless-rebuilding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!