通过XIB视图显示WebView ViewController
我有一个XIB视图和一个按钮,但是当我尝试将其配置为带有WebView的ViewController时,它会显示一些错误。
xib文件:
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)
}
}
@ibaction func paynowtowebview(_ sender:any){}}
我想在单击按钮时显示一个viewController popupview'没有成员'故事板'和类型'popupView'的值没有成员'rathing'rathing'
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样做(请记住将“主”替换为故事板的名称):
Do it like this (Remember to replace 'Main' with your storyboard name):
存在
是一种方法,故事板
是uiviewController中的两个属性
,
self.storyboard
用uistoryboard(name:“ yourname”,nil)
但对于呈现最常见的是在该视图中具有委托弱变量,该视图引用了内部视图的VC,或者您可以获取应用程序的窗口root vc,然后
vc.present(.....
present
is a method andstoryboard
is a property both of them inside aUIViewController
instance not aUIView
instanceYou can replace
self.storyboard
withUIStoryboard(name:"YourName",nil)
but forpresent
you 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(.....