在swift中从另一个viewcontroller更改webview的url

时间:2017-06-09 11:08:48

标签: ios xcode webview swift3 viewcontroller

当我点击另一个viewController上的单元格标签时,我想要在webview中重新加载Main ViewController的情况。实际上另一个viewController是一个幻灯片菜单控制器。当我点击该单元格时,我想重新加载位于webview的{​​{1}},其中包含新的网址,这实际上会让我登录网页。

请在Swift 3中提供解决方案。

有人帮忙吗?

提前致谢。

2 个答案:

答案 0 :(得分:0)

我觉得您应该在WebView和ViewController之间使用Table View委托模式tutorial

它也可以使用NSNotificationCenter(tutorial) - 但我不建议您个人使用此解决方案

答案 1 :(得分:0)

将此代码添加到viewController的viewDidLoad方法中,该方法具有webview

    NotificationCenter.default.addObserver(self, selector: #selector(reloadWebView), name: NSNotification.Name(rawValue: "load"), object: nil)

在同一个viewController中添加以下函数

    func reloadWebView(){
        //reload your webview here
    }

当滑动菜单选择发生在代码下面的Slide ViewController调用时。

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)