3

我在这里真的需要帮助。如果问题解决很明显或者我的代码很糟糕,我对 iOS/Objective-C 还是很陌生。对我轻点!!:-)

我正在努力将用于读取 QR 码的 ZBarSDK 集成到我正在构建的 iPad 应用程序中。如果我使用 ZBarReaderController(其中有很多关于实现的教程和指南),它可以正常工作。但是,我想让相机出现在 UIView 中,而不是全屏相机。

现在我已经做到了让相机视图(readerView)按预期出现在 UIView(ZBarReaderView)中,但是当它扫描代码时出现错误。在扫描代码之前不会出现错误,让我相信这与委托相关或其他原因。

这是我的代码的重要部分:(ZBarSDK.h 在 PCH 文件中导入)

SignInViewController.h

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@class AVCaptureSession, AVCaptureDevice;

@interface SignInViewController : UIViewController
< ZBarReaderDelegate >
{
    ZBarReaderView *readerView;
    UITextView *resultText;
}

@property (nonatomic, retain) UIImagePickerController *imgPicker;
@property (strong, nonatomic) IBOutlet UITextView *resultText;
@property (strong, nonatomic) IBOutlet ZBarReaderView *readerView;

-(IBAction)StartScan:(id) sender;

SignInViewController.m

#import "SignInViewController.h"

@interface SignInViewController ()

@end

@implementation SignInViewController


@synthesize resultText, readerView;

-(IBAction)StartScan:(id) sender
{
readerView = [ZBarReaderView new];
readerView.readerDelegate = self;

readerView.tracksSymbols = NO;

readerView.frame = CGRectMake(30,70,230,230);
readerView.torchMode = 0;
readerView.device = [self frontFacingCameraIfAvailable];

ZBarImageScanner *scanner = readerView.scanner;
[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];


[self relocateReaderPopover:[self interfaceOrientation]];

[readerView start];

[self.view addSubview: readerView];
resultText.hidden=NO;

}


- (void) readerControllerDidFailToRead: (ZBarReaderController*) reader
                         withRetry: (BOOL) retry{
NSLog(@"the image picker failing to read");

}

- (void) imagePickerController: (UIImagePickerController*) reader     didFinishPickingMediaWithInfo: (NSDictionary*) info
{


NSLog(@"the image picker is calling successfully %@",info);
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
NSString *hiddenData;
for(symbol in results)
    hiddenData=[NSString stringWithString:symbol.data];


NSLog(@"the symbols  is the following %@",symbol.data);

resultText.text=symbol.data;


NSLog(@"BARCODE= %@",symbol.data);

NSLog(@"SYMBOL : %@",hiddenData);
resultText.text=hiddenData;

}

扫描代码时出现的错误:

2012-12-16 14:28:32.797 QRTestApp[7970:907] -[SignInViewController     readerView:didReadSymbols:fromImage:]: unrecognized selector sent to instance 0x1e88b1c0
2012-12-16 14:28:32.799 QRTestApp[7970:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SignInViewController readerView:didReadSymbols:fromImage:]: unrecognized selector sent to instance 0x1e88b1c0'

我还不太担心结果会发生什么,只是想克服这个错误。由于 ZBarReaderView 上严重缺乏教程或文档(无论如何对于初学者),我花了很长时间才让相机出现在 UIView 中。谢谢大家。

4

1 回答 1

2

我解决了这个问题。代表姓名不正确。它应该是“ZbarReaderViewDelegate”。我错过了“视图”部分。啊!!

@interface SignInViewController : UIViewController
< ZBarReaderViewDelegate >
{
ZBarReaderView *readerView;
UITextView *resultText;
}
于 2012-12-30T01:14:32.473 回答