I have two view controllers, viewcontroller 1 and view controller 2.viewController 1 contains a webview. I push view controller 2 on top of view controller 1 when i click a link inside the webview. After barcode is scanned in viewcontroller 2 , I pass the scanned data as a function to viewcontroller1. Then i pop viewController 2 from the top of the screen. I am not able to access the webview property in viewcontroller 1 and display the barcode as a javascript alert. Appreciate your help in this.
Here is 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
Here is its corrosponding .m file
#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
Here is the barcodeScanner.m file
#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];