简体   繁体   English

无法呈现 IB Designables 的实例

[英]Failed to render instance of IB Designables

I have an Objective-C and Swift mixed dynamic framework.我有一个 Objective-C 和 Swift 混合动态框架。 And the mixed framework was linked with two pure Objective-C dynamic frameworks.并且混合框架与两个纯Objective-C 动态框架相关联。

When I tried to mark any class in the mixed framework with IB Designable and using that class in either storyboard or nib, the Xcode always says the instance of it was failed to render.当我尝试使用 IB Designable 标记混合框架中的任何类并在故事板或笔尖中使用该类时,Xcode 总是说它的实例无法呈现。

And there was the error message:还有错误信息:

IB Designables: Failed to render instance of WZUITokenField: dlopen(WZUIKit.framework, 1): Library not loaded: /Library/Frameworks/WZFoundation.framework/WZFoundation Referenced from: WZUIKit.framework Reason: image not found IB Designables:无法呈现 WZUITokenField 的实例:dlopen(WZUIKit.framework, 1):库未加载:/Library/Frameworks/WZFoundation.framework/WZFoundation 引用自:WZUIKit.framework 原因:找不到图像

IB Designables: Failed to update auto layout status: dlopen(WZUIKit.framework, 1): Library not loaded: @rpath/WZFoundation.framework/WZFoundation Referenced from: WZUIKit.framework Reason: image not found IB Designables:无法更新自动布局状态:dlopen(WZUIKit.framework, 1):库未加载:@rpath/WZFoundation.framework/WZFoundation 引用自:WZUIKit.framework 原因:找不到图像

The framework WZUIKit is an Objective-C and Swift mixed framework and the WZFoundation is pure Objective-C.框架 WZUIKit 是一个 Objective-C 和 Swift 混合框架,而 WZFoundation 是纯 Objective-C。

Plus, all these sutff work on either device or the simulator.另外,所有这些 sutff 都适用于设备或模拟器。

Finally, I solved this issue by adding $(CONFIGURATION_BUILD_DIR) in the target's build settings' Runpath Search Paths field.最后,我通过在目标的构建设置的Runpath Search Paths字段中添加$(CONFIGURATION_BUILD_DIR)解决了这个问题。

Plus, there are some additional steps you might need to do with your Xcode.此外,您可能需要对 Xcode 执行一些额外的步骤。

  1. Clear Xcode derived data for the project.清除项目的 Xcode 派生数据。 They are in ~/Library/Developer/Xcode/DerivedData它们在~/Library/Developer/Xcode/DerivedData
  2. Clean your current build by pressing K K清理当前版本
  3. Build your project构建你的项目
  4. In storyboard go to Editor menu and do Refresh All Views ;在故事板中,转到Editor菜单并执行Refresh All Views wait for build to be completed and errors should be gone等待构建完成,错误应该消失

Credit to @Mojtaba归功于@Mojtaba

如果您在构建 Mac 应用程序时@loader_path/../Frameworks同样的问题,将@loader_path/../Frameworks添加到Runpath Search Paths为我解决了这个问题。

for me it works to close xcode and reopen it again.对我来说,它可以关闭 xcode 并再次重新打开它。 No errors after.之后没有错误。 Thanks.谢谢。

I hit this error on a framework containing IBDesignables.我在包含 IBDesignables 的框架上遇到了这个错误。

I had to add $(FRAMEWORK_SEARCH_PATHS) to the LD_RUNPATH_SEARCH_PATHS setting on my framework target.我必须将$(FRAMEWORK_SEARCH_PATHS)添加到我的框架目标上的LD_RUNPATH_SEARCH_PATHS设置。

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.甚至不必清理构建文件夹。

在此处输入图片说明

Interesting.有趣的。

First, WeZZard's answer got me going in the right direction but wasn't exactly my solution.首先,WeZZard 的回答让我朝着正确的方向前进,但并不是我的解决方案。

In my iOS project, something had overridden the Runpath Search Paths field in my target.在我的 iOS 项目中,某些东西覆盖了目标中的Runpath Search Paths字段。 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.我尝试了他添加$(CONFIGURATION_BUILD_DIR)解决方案,但它对我不起作用。 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.如果我深入研究我的 xcconfig 文件,它似乎来自 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. @loader_path是关键,这似乎与 Alex 相同,但它在 iOS 上的路径与在 Mac OS X 上的路径略有不同。

I had same problem In Xcode 6.4, adding Test target membership to the storyboard fixed these errors for me.我遇到了同样的问题 在 Xcode 6.4 中,将测试目标成员资格添加到故事板为我修复了这些错误。

Also my test target has @loader_path/Frameworks set in Runpath Search Paths for test target, and not in original target.此外,我的测试目标在测试目标的运行Runpath Search Paths设置了@loader_path/Frameworks ,而不是在原始目标中。

在此处输入图片说明

I also experienced this on a Mac project and Xcode 7.3.1.我也在 Mac 项目和 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.只需转到目标的通用/链接框架和库选项卡并将违规框架的状态从必需更改为可选,即可允许 IBDesignables 在 IB 中正确更新和绘制。

可选状态

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:当我使用“Editor -> Debug Selected Views”时,我看到它崩溃了,因为我使用 CoreGraphics 创建图像并将其用作按钮的背景图像:

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).原因很简单,大小是 (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!但是在 IB 中 self.bounds.size 此时仍然为 0! 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... Apple 应该提供一份关于 IB 的注意事项清单......

In my case, I was doing the next in the initWithFrame/initWithCoder methods to create the view:就我而言,我在 initWithFrame/initWithCoder 方法中执行下一个操作来创建视图:

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.但看起来我不应该使用 Main Bundle 而是类的 bundle。 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.我在 OS X 项目中遇到了这个问题。

In my case, the problem was an old project ( NMSSH ) containing a framework target with bad build settings.就我而言,问题是一个旧项目 ( NMSSH ) 包含具有错误构建设置的框架目标。 Specifically:具体来说:

  • INSTALL_PATH was set to @executable_path/../Frameworks , but the correct setting is /Library/Frameworks INSTALL_PATH被设置为@executable_path/../Frameworks ,但正确的设置是/Library/Frameworks
  • SKIP_INSTALL was not set and defaults to NO , but the correct setting is YES SKIP_INSTALL未设置,默认为NO ,但正确设置为YES
  • DYLIB_INSTALL_NAME_BASE was not set, but the correct setting is @rpath DYLIB_INSTALL_NAME_BASE未设置,但正确的设置是@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.将设置更改为正确的值后,Xcode 能够在故事板中加载我的@IBDesignable视图。

In my case it inside private pod.在我的情况下,它在私人吊舱内。 Xcode Version 10.3 (10G8) Xcode 版本 10.3 (10G8) 产生渲染错误

The solution is very simple in my case - I just forget to add public in-between of @IBInspectable var就我而言,解决方案非常简单 -我只是忘记@IBInspectable var之间添加public

right variant:正确的变体:

import UIKit

@IBDesignable public class BorderedView: UIView {
    @IBInspectable public var borderColor: UIColor? = UIColor.white {
        didSet {
            if let actualColor = borderColor {
                layer.borderColor = actualColor.cgColor
            } else {
                layer.borderColor = UIColor.white.cgColor
            }
            
            setNeedsDisplay()
        }
    }
    @IBInspectable public var borderWidth: CGFloat = 1 {
        didSet {
            layer.borderWidth = borderWidth
            setNeedsDisplay()
        }
    }
}

PS: Editor -> Debug Selected Views did nothing in my case PS:编辑器 -> 调试选定的视图在我的情况下没有做任何事情

PS2 : AlignedCollectionViewFlowLayout pod from the dependency of my private pod and definitely not relevant to this issue. PS2 : AlignedCollectionViewFlowLayout pod 来自我的私有 pod 的依赖,绝对与这个问题无关。

PS3: Issue still here PS3:问题仍然存在

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

[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 ):我在使用Cocoapods 1.9.1时遇到了类似的问题,错误消息与path error ,如下所示(我添加了 NewLines 以确保 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这是该线程的链接: 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规则在你的最后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然后再次执行pod install ,它现在应该可以工作了

Hope it helps~希望有帮助~

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.)如果storyboard中有任何冲突,请正确解决它们,检查xml是否正确验证。(这是主要步骤。)
  2. Clean the project.清理项目。
  3. Delete the derived data folder.删除派生数据文件夹。
  4. Quit Xcode and restart it again.退出 Xcode 并重新启动它。 (I had to do this twice.) (我不得不这样做两次。)

Clear Derived Data .清除派生数据。 Quit Xcode, Reopen again.退出 Xcode,重新打开。

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

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