Ios 从appDelegate调用viewcontroller webview方法

Ios 从appDelegate调用viewcontroller webview方法,ios,objective-c,uiviewcontroller,uiwebview,Ios,Objective C,Uiviewcontroller,Uiwebview,我的viewcontroller中有一个webview 我集成了FacebookConnect,它从AppDelegate.m文件中抛出userLoggedIn+userLoggedOut函数 我需要从这些登录/注销函数将javascript运行到webview中,如下所示: [_crawlWebViewStringByEvaluatingJavaScriptFromString:@“警报('hey ho')”] 上面这一行在保存webview的viewcontroller中工作得很好,但在ap

我的viewcontroller中有一个webview

我集成了FacebookConnect,它从AppDelegate.m文件中抛出userLoggedIn+userLoggedOut函数

我需要从这些登录/注销函数将javascript运行到webview中,如下所示: [_crawlWebViewStringByEvaluatingJavaScriptFromString:@“警报('hey ho')”]


上面这一行在保存webview的viewcontroller中工作得很好,但在appDelegate中则不行。怎么办?

您需要将请求从
AppDelegate
转发到拥有WebView的
ViewController

如果这行代码在ViewController中起作用

[ _crawlWebView stringByEvaluatingJavaScriptFromString: @"alert('hey ho')" ];
首先,确保您的
AppDelegate
具有指向
ViewController
的指针,其次,确保webView通过属性可用

然后从AppDelegate使用指针和属性,最终得到如下结果:

[myViewController.crawlWebView stringByEvaluatingJavaScriptFromString: @"alert('hey ho')" ];