IB Designables: Failed to render and update auto l

2020-02-07 19:05发布

I have a custom view (xib) that has a UIButton inside of it, I made id IBDesignable doing the following:

UserView.swift

import UIKit

@IBDesignable
class UserView: UIView {

    @IBOutlet var view: UIView!
    @IBOutlet weak var userButton: UIButton!

    override init(frame: CGRect) {
        super.init(frame: frame)
        load()

    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        load()
    }

    fileprivate func load() {
        Bundle.main.loadNibNamed("UserView", owner: self, options: nil)
        addSubview(view)
        self.frame = bounds
    }

}

UserView.xib

  • Added the UIButton and set constraints
  • Set the File's Owner: UserView

Storyboard

I added a UIView to a Bar Button Item and assigned UserView class but nothing is rendering, and I got the following build error:

error: IB Designables: Failed to render and update auto layout status for FoodViewController (bR3-Kz-wX7): The agent threw an exception.

My currently environment: Xcode 9, Swift 4

13条回答
beautiful°
2楼-- · 2020-02-07 20:02

Unfortunately, you can't use IBOutlets within a IBDesignable. Better answer for you here:

Live Render IBOutlet Connected Subviews Via IBInspectable Properties

Perhaps you wanted to have your UserView extend UIButton, rather than UIView?

查看更多
贼婆χ
3楼-- · 2020-02-07 20:03

I add this script at the end of my Podfile and performed pod install again. So I could build normally my project.

post_install do |installer|
    installer.pods_project.build_configurations.each do |config|
        config.build_settings.delete('CODE_SIGNING_ALLOWED')
        config.build_settings.delete('CODE_SIGNING_REQUIRED')
    end
end
查看更多
神经病院院长
4楼-- · 2020-02-07 20:04

I just had the exact same issue, and the only thing that worked for me was instead of using the main Bundle I had to get the Bundle for the Nib I wanted. Essentially changing:

Bundle.main.loadNibNamed("UserView", owner: self, options: nil)

To:

let bundle = Bundle(for: UserView.self)
bundle.loadNibNamed("UserView", owner: self, options: nil)

Which is bizarre, as in my case when comparing the two Bundles at runtime in LLDB they were identical (class name is different but the rest of my setup was identical to the OP)

lldb screenshot Updated

Why loading NIB from main bundle does not work?

Because when InterfaceBuilder is rendering it is not running the application. There is no "main application bundle".

查看更多
聊天终结者
5楼-- · 2020-02-07 20:05

For me this problem solved by,

  1. Updating pods.
  2. Changing build setting to '$(inherited)' for swift libraries embedded option.
  3. Building, cleaning, building.
  4. Closing project.
  5. Quitting Xcode.
  6. Running again.

hahaha old hack :) Thanks!

查看更多
Emotional °昔
6楼-- · 2020-02-07 20:06

Xcode 9.3, CocoaPods 1.5.3 It may be due to recent update on CocoaPods version. See issue here.

I had this error IB Designables: Failed to render and update auto layout status in the storyboard, the class STPPaymentCardTextField in Stripe SDK related to Cocoapods.

Solution is to downgrade your CocoaPods to 1.4.0.

sudo gem list cocoapods

sudo gem uninstall cocoapods

sudo gem install cocoapods -v 1.4.0

pod update
查看更多
我想做一个坏孩纸
7楼-- · 2020-02-07 20:06

It is the problem with some cocoa pods versions like 1.5.0. If you are using this one then it cause to rendering failed to move from current version to other run this commands in terminal

sudo gem uninstall cocoapods

You can install any specific version by mentioning like this

sudo gem install cocoapods -v 1.4.0

Hope it will works for you.

查看更多
登录 后发表回答