I have a xib view and a button in it but when i try to configure it to present a ViewController with a WebView it shows some errors.
the xib file:
class popUpView: UIView, UITextFieldDelegate {
@IBOutlet weak var payNowPopUp: UIButton!
@IBOutlet weak var priceTextFieldPopUp: UITextField!
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override init(frame: CGRect) {
super.init(frame: frame)
xibSetup(frame:CGRect(x: 0, y: 0, width: frame.width, height: frame.height))
}
func xibSetup(frame: CGRect){
let view = loadXib()
view.frame = frame
addSubview(view)
popUpViewInterface.layer.cornerRadius = 10
}
func loadXib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "popUpView", bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil).first as? UIView
return view!
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
priceTextFieldPopUp.resignFirstResponder()
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
priceTextFieldPopUp.resignFirstResponder()
return true
}
@IBAction func payNowToWebView(_ sender: Any) {
guard let mainTabBarController = self.storyboard?.instantiateViewController(withIdentifier: "paymentWebView")
else {
return
}
mainTabBarController.modalPresentationStyle = .custom
self.present(mainTabBarController, animated: true, completion: nil)
}
}
Inside the @IBAction func payNowToWebView(_ sender: Any) { } I want to present a viewController when the button is clicked but it's showing some errors like: Value of type 'popUpView' has no member 'storyboard' and Value of type 'popUpView' has no member 'present'
presentis a method andstoryboardis a property both of them inside aUIViewControllerinstance not aUIViewinstanceYou can replace
self.storyboardwithUIStoryboard(name:"YourName",nil)but forpresentyou need a vc to show the needed one from it most commonly to have a delegate weak variable inside that view that references the vc where the view is inside or you may get the app's window root vc thenvc.present(.....