IB Designables: Failed to render and update auto layout status

后端 未结 14 1135
花落未央
花落未央 2020-12-13 04:11

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

UserView.swif

相关标签:
14条回答
  • 2020-12-13 05:03

    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?

    0 讨论(0)
  • 2020-12-13 05:05

    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)

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

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