Failed to render instance of IB Designables

我与影子孤独终老i 提交于 2019-11-28 03:15:06
WeZZard

Finally, I solved this issue by adding $(CONFIGURATION_BUILD_DIR) in the target's build settings' Runpath Search Paths field.

Plus, there are some additional steps you might need to do with your Xcode.

  1. Clear Xcode derived data for the project. They are in ~/Library/Developer/Xcode/DerivedData
  2. Clean your current build by pressing K
  3. Build your project
  4. In storyboard go to Editor menu and do Refresh All Views; wait for build to be completed and errors should be gone

Credit to @Mojtaba

If you have the same issue building a Mac App, adding @loader_path/../Frameworks to Runpath Search Paths solved this for me.

for me it works to close xcode and reopen it again. No errors after. Thanks.

I hit this error on a framework containing IBDesignables.

I had to add $(FRAMEWORK_SEARCH_PATHS) to the LD_RUNPATH_SEARCH_PATHS setting on my framework target.

After updating the runpath setting, building, and refreshing the view in the storyboard, the error went away. Didn't even have to clean the build folder.

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.

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.

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...

Doug Hanson

I also experienced this on a Mac project and Xcode 7.3.1. In my case, the framework referenced in the Failed to Render error message was not related to drawing at all.

Simply going to the target's General/Linked Frameworks and Libraries tab and changing the offending framework's Status from Required to Optional allowed the IBDesignables to update and draw properly in IB.

In my case, I was doing the next in the initWithFrame/initWithCoder methods to create the view:

className = NSStringFromClass([self class]);
self.view = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] firstObject];

But It looks like I was not supposed to use the Main Bundle but the bundle of the class. So I replaced that code for the following and it worked:

bundle = [NSBundle bundleForClass:[self class]];
className = NSStringFromClass([self class]);
self.view = [[bundle loadNibNamed:className owner:self options:nil] firstObject];

I thought maybe this might help somebody.

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.

komall

Follow the below steps:

  1. If there are any conflicts in the storyboard, resolve them correctly, check if the xml is correctly validated.(These is main step.)
  2. Clean the project.
  3. Delete the derived data folder.
  4. Quit Xcode and restart it again. (I had to do this twice.)

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()
}

Clear Derived Data . Quit Xcode, Reopen again.

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