Ios 从另一个viewController调用web视图
我在主Ios 从另一个viewController调用web视图,ios,objective-c,webview,uiviewcontroller,Ios,Objective C,Webview,Uiviewcontroller,我在主UIViewController上有一个UIWebView,工作正常。我使用此命令发送数据,再次说明一切正常: [self.dWebView stringByEvaluatingJavaScriptFromString: myString]; 问题是我添加了另一个UIViewController(QRViewController)从QR标签读取数据,我希望以相同的方式发送数据。 这是我在QRViewController上的代码,但什么也没发生: ViewController* _view
UIViewController
上有一个UIWebView
,工作正常。我使用此命令发送数据,再次说明一切正常:
[self.dWebView stringByEvaluatingJavaScriptFromString: myString];
问题是我添加了另一个UIViewController
(QRViewController
)从QR标签读取数据,我希望以相同的方式发送数据。
这是我在QRViewController
上的代码,但什么也没发生:
ViewController* _viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[_viewController.dWebView stringByEvaluatingJavaScriptFromString: qrString];
有可能这样做吗?有什么东西不见了吗
提前感谢。将NSString*str对象添加到您的ViewController中 将其传递为:_viewController.str=qrString [self.dWebView stringByEvaluatingJavaScriptFromString:self.str]
这将起作用您正在通过调用以下代码创建同一
UIViewController
类的第二个实例:
ViewController* _viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
\u viewController
未指向屏幕上可见的副本,它是当前未显示的新副本
您需要获取当前显示的上一个实例的句柄,并将数据传递回该实例。这将取决于您如何构建此应用程序
例如:
- 如果以MODALY方式显示,则需要获取
self.presentingViewController
- 如果您使用的是navigationController,则可以访问它的
属性以获取之前的属性的句柄viewControllers