【发布时间】:2014-02-22 05:01:26
【问题描述】:
我有两个视图控制器,视图控制器 1 和视图控制器 2。视图控制器 1 包含一个 webview。当我单击 webview 内的链接时,我将视图控制器 2 推到视图控制器 1 的顶部。在 viewcontroller 2 中扫描条形码后,我将扫描的数据作为函数传递给 viewcontroller1。然后我从屏幕顶部弹出 viewController 2。我无法访问 viewcontroller 1 中的 webview 属性并将条形码显示为 javascript 警报。感谢您在这方面的帮助。
这里是 viewController 1
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ADMSViewController : UIViewController <UIWebViewDelegate>
{
}
@property (nonatomic,retain) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@property (nonatomic) BOOL restoringState;
- (IBAction)backButtonPressed:(id)sender;
-(void)pasteVinInTextBox : (NSString *)vin;
@end
这是它对应的 .m 文件
#import "ADMSViewController.h"
@implementation ADMSViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_webView setDelegate:self];
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com/"]]];
}
//- (void)didReceiveMemoryWarning //{ // [super didReceiveMemoryWarning]; // // Dispose of any resources that can be recreated. //}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated]; }
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated]; }
-(void)webViewDidStartLoad:(UIWebView *)webView {
[_activityIndicator startAnimating]; }
- (void)viewDidUnload {
[super viewDidUnload]; }
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[_activityIndicator stopAnimating]; }
- (IBAction)backButtonPressed:(id)sender {
[_webView goBack]; }
-(void)pasteVinInTextBox:(NSString *)vin {
NSLog(@"%@",vin);
_webView = [[UIWebView alloc]init];
[_webView stringByEvaluatingJavaScriptFromString:@"alert('Trigger the JS!');"]; }
@end
这是barcodeScanner.m文件
#import "ADMSBarcodeScanner.h"
@implementation ADMSBarcodeScanner
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationLandscapeRight);
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
【问题讨论】:
-
请详细说明“不工作”
-
google 有一个主文本框。我正在将该页面加载到 UIWebView 中。假设当我单击后退按钮时,它会打开 admsbarcode 扫描仪视图控制器。扫描后,我想将文本粘贴到文本框中。
标签: javascript ios objective-c uiwebview