2 // RootViewController.m
5 // Created by David Kavanagh on 5/10/10.
6 // Copyright __MyCompanyName__ 2010. All rights reserved.
9 #import "RootViewController.h"
10 #import "QRCodeReader.h"
13 @interface RootViewController()
18 @implementation RootViewController
19 @synthesize resultsView;
20 @synthesize resultsToDisplay;
22 #pragma mark View lifecycle
26 [self setTitle:@"ZXing"];
29 - (IBAction)scanPressed:(id)sender {
31 ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
32 QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
33 NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
34 [qrcodeReader release];
35 widController.readers = readers;
37 NSBundle *mainBundle = [NSBundle mainBundle];
38 [widController setSoundToPlay:[[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO] retain]];
39 [self presentModalViewController:widController
41 [widController release];
45 - (void)viewWillAppear:(BOOL)animated {
46 [super viewWillAppear:animated];
49 [resultsView setText:resultsToDisplay];
50 [resultsView setNeedsDisplay];
55 - (void)viewDidAppear:(BOOL)animated {
56 [super viewDidAppear:animated];
60 - (void)viewWillDisappear:(BOOL)animated {
61 [super viewWillDisappear:animated];
65 - (void)viewDidDisappear:(BOOL)animated {
66 [super viewDidDisappear:animated];
71 // Override to allow orientations other than the default portrait orientation.
72 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
73 // Return YES for supported orientations.
74 return (interfaceOrientation == UIInterfaceOrientationPortrait);
79 #pragma mark ZXingDelegateMethods
81 - (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result {
82 [self dismissModalViewControllerAnimated:NO];
83 self.resultsToDisplay = result;
86 - (void)zxingControllerDidCancel:(ZXingWidgetController*)controller {
87 [self dismissModalViewControllerAnimated:YES];
92 #pragma mark Memory management
94 - (void)didReceiveMemoryWarning {
95 // Releases the view if it doesn't have a superview.
96 [super didReceiveMemoryWarning];
98 // Relinquish ownership any cached data, images, etc that aren't in use.
101 - (void)viewDidUnload {
102 // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
103 // For example: self.myOutlet = nil;
108 [resultsView release];
109 [resultsToDisplay release];