Reputation: 276
My app is crashing, but there is no additional information as to why. When I go to a certain view controller, it requires loading a custom UIView
from a nib. The line to load the nib is where I am getting the crash.
I get an error message of
Thread 1: EXC_BAD_ACCESS (code=2, address=0x16b547db8)
but there is no output to the console or further information.
Scheme is set to debug. I've tried intentionally making an error in the spelling of the nib name, and that gives me all of the necessary debug information in the console.
The line causing the crash is:
let v = Bundle.main.loadNibNamed("HelpPageSection", owner: self, options: nil)![0] as! HelpPageSection
Upvotes: 0
Views: 287
Reputation: 276
I added some comments to print when the initializer was being called, and it was indeed an infinite loop. However, there were still issues. I tried a slightly different way of loading the nib and it works. I connected the base view of the xib file as an IBOutlet, then used this code:
@IBOutlet var main: UIView!
func commonInit() {
Bundle.main.loadNibNamed("HelpPageSection", owner: self, options: nil)
self.addSubview(self.main)
}
override init(frame: CGRect) {
super.init(frame: frame)
self.commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.commonInit()
}
Upvotes: 0
Reputation: 1679
To load an xib:-
let v = Bundle.main.loadNibNamed("HelpPageSection", owner: self, options: nil)?.first as! HelpPageSection
It helps.
Upvotes: 0