I'm a Swift beginner, and I'm stacking on using CustomView Xib Files on Swift.
I have five CustomViews, named HogeAView~HogeEView respectively.
From HogeAView to HogeCView, the view can loaded without describing any errors, and enabled to interact all outlets which I placed.
But HogeDView and HogeEView, that made same way as other three views are not working. Both Views are loaded, but all outlets which I placed returns no responses when I interacted. (e.g. UIButton doesn't make a flash when the button was pressed)
I confirmed Files'owner UIViewClass is correct, same name as written in Code, and there's no absurd Views which prevents interacting.
Please give me a solution if you know how to solve the problem.
Thank you.
import UIKit
class HogeDView: UIView {
override init(frame: CGRect){
super.init(frame: frame)
loadNib()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
loadNib()
}
func loadNib(){
let view = Bundle.main.loadNibNamed("HogeDView", owner: self, options: nil)?.first as! UIView
view.frame = self.bounds
self.addSubview(view)
}
}
import UIKit
class HogeDViewController: UIViewController {
override func loadView() {
super.loadView()
}
override func viewDidLoad() {
super.viewDidLoad()
self.view = HogeDView()
}
}
- Filled HogeDView class in the **File's owner **, not in the view of the hierarchy in Xid Files.
- Retried making HogeDview, and HogeDController.
- Confirmed there is no absurd view upper front.
- Confirmed UIConnection is Correct
My first code was a copy of online tutorial...and it should had to be worked correctly...basically the tutorial I found was totally wrong.
DonMag's comments helped me to solve the issue.
To Donmag, and HangarRash, thank you for giving me a feedback.