简体   繁体   English

使用Swift从推送通知appdelegate更改视图控制器中UIWebView的URL

[英]change URL of UIWebView in view controller from push notification appdelegate with Swift

 var storyboard = UIStoryboard(name: "Main", bundle: nil)
 var viewController: UIViewController = storyboard.instantiateViewControllerWithIdentifier("view0000") as UIViewController
 self.window?.rootViewController = viewController
 self.window?.makeKeyAndVisible()

how to get UIWebView in appdelegate.swift 如何在appdelegate.swift获取UIWebView

Create a property for the URL in your viewcontroller and set the value for the property in AppDelegage. 在视图控制器中为URL创建一个属性,然后在AppDelegage中设置该属性的值。 Then in your ViewConroller's viewDidLoad method, set the URL property value to your UIWebView. 然后在ViewConroller的viewDidLoad方法中,将URL属性值设置为UIWebView。

Like Rshankar said, assuming your viewController has the webView, I would do: 就像Rshankar所说的那样,假设您的viewController具有webView,我会这样做:

var storyboard = UIStoryboard(name: "Main", bundle: nil)
var viewController: MyViewController = storyboard.instantiateViewControllerWithIdentifier("view0000") as MyViewController
viewController.url = "http://stackoverflow.com"
self.window?.rootViewController = viewController
self.window?.makeKeyAndVisible()

And this would be your MyViewController: And whatever you want in reloadWebview 这就是您的MyViewController:无论您要在reloadWebview中使用什么

class MyViewController:UIViewController {
    var url = "" {
        didSet {
            reloadWebView()
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM