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

时间:2015-03-10 03:54:34

标签: ios swift uiwebview

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

如何在UIWebView

中获取appdelegate.swift

2 个答案:

答案 0 :(得分:0)

在viewcontroller中为URL创建属性,并在AppDelegage中设置属性的值。然后在ViewConroller的viewDidLoad方法中,将URL属性值设置为UIWebView。

答案 1 :(得分:0)

像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()

这将是你的MyViewController: 无论你想在reloadWebview

中做什么
class MyViewController:UIViewController {
    var url = "" {
        didSet {
            reloadWebView()
        }
    }
}