通过XIB视图显示WebView ViewController

发布于 2025-01-27 15:05:41 字数 1632 浏览 3 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

洋洋洒洒 2025-02-03 15:05:42

这样做(请记住将“主”替换为故事板的名称):

@IBAction func payNowToWebView()  {

        let storyboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil)
        let vc: paymentWebView = storyboard.instantiateViewControllerWithIdentifier("paymentWebView") as! PaymentWebView
        let currentController = self.getRootVC()
        currentController?.presentViewController(vc, animated: false, completion: nil)

    }

func getRootVC() -> UIViewController? {

    if let rootController = UIApplication.shared.keyWindow?.rootViewController {
        var currentController: UIViewController! = rootController
        while( currentController.presentedViewController != nil ) {
            currentController = currentController.presentedViewController
        }
        return currentController
    }
    return nil

}

Do it like this (Remember to replace 'Main' with your storyboard name):

@IBAction func payNowToWebView()  {

        let storyboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil)
        let vc: paymentWebView = storyboard.instantiateViewControllerWithIdentifier("paymentWebView") as! PaymentWebView
        let currentController = self.getRootVC()
        currentController?.presentViewController(vc, animated: false, completion: nil)

    }

func getRootVC() -> UIViewController? {

    if let rootController = UIApplication.shared.keyWindow?.rootViewController {
        var currentController: UIViewController! = rootController
        while( currentController.presentedViewController != nil ) {
            currentController = currentController.presentedViewController
        }
        return currentController
    }
    return nil

}
带刺的爱情 2025-02-03 15:05:42

存在是一种方法,故事板uiviewController中的两个属性

self.storyboarduistoryboard(name:“ yourname”,nil)但对于呈现最常见的是在该视图中具有委托弱变量,该视图引用了内部视图的VC,或者您可以获取应用程序的窗口root vc,然后vc.present(.....

present is a method and storyboard is a property both of them inside a UIViewController instance not a UIView instance

You can replace self.storyboard with UIStoryboard(name:"YourName",nil)but for present 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 then vc.present(.....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文