Einfache IF-Anweisungen in Xcode

Im mit die ZBar Reader SDK

.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
//ADD: delegate protocol
< ZBarReaderDelegate >
{
UIImageView *resultImage;
UITextView *resultText;
UILabel *text;
}
@property (nonatomic, retain) IBOutlet UIImageView *resultImage;
@property (nonatomic, retain) IBOutlet UITextView *resultText;
@property (nonatomic, retain) IBOutlet UILabel *text;
- (IBAction) scanButtonTapped;

@end

UITextView *resultText;
IBOutlet UILabel *text;

.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize resultImage, resultText, text;

- (IBAction) scanButtonTapped
{
//ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;

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];

//present and release the controller
[self presentModalViewController: reader
                        animated: YES];

}





- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
//ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
    //EXAMPLE: just grab the first barcode
    break;

//EXAMPLE: do something useful with the resulting data
resultText.text = symbol.data;


//Below are the IF Statements...
if ((symbol = @"3307210410801")) {
    text.text = @"FarCry 2";
}
else if ((symbol = @"530917119347")) {
    text.text = @"Call of Duty: Black Ops 2";
}
else if ((symbol = @"5021290053694")) {
    text.text = @"Hitman Absolution";
}
else if ((symbol = @"5026555401739")) {
    text.text = @"Red Dead Redemption";
}




//EXAMPLE: do something useful with the barcode image
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];

//ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}




- (void) dealloc
{
self.resultImage = nil;
self.resultText = nil;
self.text = nil;


}


- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
return(YES);
}

- (void)viewDidLoad
{
[super viewDidLoad];
//Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}

@end

Funktioniert es so, dass, wenn resultText zeigt auf meinem Simulator zu 5021290053694 dann die "text" - zeigt "Pingu"

Mein problem ist, dass Pingu nicht verschwinden, wenn die nächste Nummer erscheint, also, wenn 5026555401739 zeigt, dann werden 'text' sollte zeigen, "Shaun of the Dead". Stattdessen bleibt es wie Pingu.

In anderen Worten, es nicht freigeben, die je nachdem, was 'text' wurde zuerst angezeigt. Die erste wird dort bleiben, bis ich, schließen Sie die App herunter und Öffnen Sie.

Hoffentlich ist dies leicht zu verstehen. 🙂

Vielen Dank im Voraus.

  • Nick

BEARBEITEN

Schreibe einen Kommentar