I have created UIView in storyboard (Xcode 8.2.1). I reference the things inside to UIView class name LoginView
. I delete one things by mistake then I got error at the line of Bundle.main.loadNibNamed("LoginView", owner: self, options: nil)
. EXC_BAD_ACCESS(code=2,....)
I read about this in some answer here, they said about referencing missing. I try to reference everything again but still error. I'm now confusing about what should I reference it to. File Owner or View.
EDIT : The bug is happen when this View is render.
LoginView.swift
import UIKit
class LoginView: UIView {
@IBOutlet var view: UIView!
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!
@IBOutlet weak var forgotPasswordBtn: UIButton!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Bundle.main.loadNibNamed("LoginView", owner: self, options: nil)
self.addSubview(view)
view.frame = self.bounds
emailField.becomeFirstResponder()
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIInputViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
}
func dismissKeyboard() {
view.endEditing(true)
}
}
This is my components in LoginView StoryBoard
And this is my referencing.
There's a CocoaPod called NibDesignable that not only configures the nib into the view (with constraints), but also makes the view
IBDesignable
so you can see your nib-based-views in the storyboard.NibDesignable requires you to change the nib's file owner to the view class rather than the nib's view's custom class. Also, outlet connections must be made from the file's owner and not from the nib's view.