Failed to render instance of IB Designables

前端 未结 15 655
情深已故
情深已故 2020-12-07 12:09

I have an Objective-C and Swift mixed dynamic framework. And the mixed framework was linked with two pure Objective-C dynamic frameworks.

When I tried to mark any cl

相关标签:
15条回答
  • 2020-12-07 12:34

    I had a similar error which was caused by my Framework's views not having public initialisers:

    public override init(frame: CGRect) {
        super.init(frame:frame)
        commonInit()
    }
    
    required public init(coder: NSCoder) {
        super.init(coder: coder)
        commonInit()
    }
    
    0 讨论(0)
  • 2020-12-07 12:37

    [I put this answer here for people like me finding this very similar thread without being able to find a solution]

    I had a similar issue while using Cocoapods 1.9.1, the error message was related to a path error as follow (I added NewLines for the sake of lisibility):

    error: IB Designables: 
    
    Failed to render and update auto layout status for 
    
    UITableViewController (kDz-VB-YcS): 
    
    dlopen(YOUR_FRAMEWORK.framework, 1): 
    
    Library not loaded: @rpath/YOUR_FRAMEWORK.framework/YOUR_FRAMWORKReferenced
    
    from: YOUR_FRAMEWORK.frameworkReason: image not found
    
    

    Here is the link to the thread: Cocoapods Issue 7606

    And in the comments, someone posted a solution (that works for me). You need to put this post_install rule at the very end of your Podfile:

    post_install do |installer|
      installer.pods_project.build_configurations.each do |config|
        next unless config.name == 'Debug'
        config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = [
          '$(FRAMEWORK_SEARCH_PATHS)'
        ]
      end
    end
    

    Then execute again pod install, and it should now works

    Hope it helps~

    0 讨论(0)
  • 2020-12-07 12:38

    I had same problem In Xcode 6.4, adding Test target membership to the storyboard fixed these errors for me.

    Also my test target has @loader_path/Frameworks set in Runpath Search Paths for test target, and not in original target.

    enter image description here

    0 讨论(0)
  • 2020-12-07 12:43

    I had this problem in an OS X project.

    In my case, the problem was an old project (NMSSH) containing a framework target with bad build settings. Specifically:

    • INSTALL_PATH was set to @executable_path/../Frameworks, but the correct setting is /Library/Frameworks
    • SKIP_INSTALL was not set and defaults to NO, but the correct setting is YES
    • DYLIB_INSTALL_NAME_BASE was not set, but the correct setting is @rpath

    Note that all of the correct settings are what you get automatically for a newly-created framework target.

    After changing the settings to the correct values, Xcode was able to load my @IBDesignable view in the storyboard.

    0 讨论(0)
  • 2020-12-07 12:44

    Interesting.

    First, WeZZard's answer got me going in the right direction but wasn't exactly my solution.

    In my iOS project, something had overridden the Runpath Search Paths field in my target. It looked like this:

    LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
    

    I tried his solution of adding the $(CONFIGURATION_BUILD_DIR) but it didn't work for me. Since it wasn't working, out of habit I just deleted the configuration entry (going back to project defaults). When I did, it reset to this:

    LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
    

    which if I dig into my xcconfig files, appears to come from the Cocoapods.

    It seems same as Alex that the @loader_path is key, but it's a slightly different path on iOS than it is Mac OS X.

    0 讨论(0)
  • 2020-12-07 12:46

    I just figured out another reason in my case:

    When I used 'Editor -> Debug Selected Views' I saw that it crashed, because I was using CoreGraphics to create an image and use it as background image for a button:

    class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {
    
        let rect = CGRectMake(0.0, 0.0, size.width, size.height);
        UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0);
        let context = UIGraphicsGetCurrentContext();    // It's alraedy nil here :(
    
        CGContextSetFillColorWithColor(context, color.CGColor);
        CGContextFillRect(context, rect);
    
        let image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return image;
    
    }
    

    The reason is simply that size is (0.0, 0.0). Why is that? I am calling

    super.setBackgroundImage(UIImage.imageWithColor(bgColor, size: self.bounds.size), forState: .Normal)
    

    But in IB self.bounds.size is still 0 at this point! So I changed one line:

    let rect = CGRectMake(0.0, 0.0, max(size.width, 1.0), max(size.height, 1.0));
    

    And now it works :)

    Apple should provide a list with Dos and Don'ts regarding the IB...

    0 讨论(0)
提交回复
热议问题