0Day Forums
Could not load IBDesignable xib in the Interface Builder - Printable Version

+- 0Day Forums (https://zeroday.vip)
+-- Forum: Coding (https://zeroday.vip/Forum-Coding)
+--- Forum: Swift (https://zeroday.vip/Forum-Swift)
+--- Thread: Could not load IBDesignable xib in the Interface Builder (/Thread-Could-not-load-IBDesignable-xib-in-the-Interface-Builder)



Could not load IBDesignable xib in the Interface Builder - aridness684522 - 07-19-2023

I have a `xib` (`childXib`) file linked to its custom `UIView` swift file through its Owner.

This is how I initialize my custom `UIView`:

// init for IBDesignable
override init(frame: CGRect) {
super.init(frame: frame)

let view = loadViewFromNib()
view.frame = bounds

addSubview(view)
}

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

func loadViewFromNib() -> UIView {

let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "CommentCellView", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

return view
}

When I want to add this `xib` (`childXib`) in another `xib` (`parentXib`), I get the following errors:

> error: IB Designables: Failed to render instance of MyRootView: The agent threw an exception.

Where `MyRootView` is the file linked to `parentXib`

> error: IB Designables: Failed to update auto layout status: The agent raised a "NSInternalInconsistencyException" exception: Could not load NIB in bundle: 'NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Overlays> (loaded)' with name 'MyIBDesignableCustomViewFilename'

Where `MyIBDesignableCustomViewFilename` is the file linked to `childXib`.

When I debug it by clicking on `Debug` in `Custom class` from the `Identity inspector`, it doesn't work from that line:

let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

All the `xib` files are in `Copy Bundle Resources` in `Build Phases`.

Any idea what's wrong?