I'm trying to load a VC from xib and present it on top of other VCs. It's displayed fine, but its buttons aren't working although they visually respond to taps. All connections in Interface Builder are set up correctly. When I, for example, change button title programmatically in MyVC, it's changed as expected. This is how I load my view controller from xib:
MyVC.swift:
public init() {
super.init(nibName:String(describing: MyVC.self), bundle:bundleName)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Showing it:
public func show() {
if let rootView = UIApplication.shared.keyWindow {
view.frame = rootView.bounds
rootView.addSubview(view)
}
}
In another VC somewhere in the app:
MyVC.show()
There was a similar question without an answer: Load a UIView from nib in Swift
Update:
This is the code for the button
@IBOutlet var dismissButton: UIButton!
@IBAction func dismissPopup() {
view.removeFromSuperview()
}
A breakpoint in dismissPopup() is never triggered