2012-12-16 87 views
3

我真的需要幫助。我對iOS/Objective-C相當陌生,所以很抱歉,如果問題解決方案很明顯,或者我的代碼很糟糕。輕鬆點我! :-)在UIView中實現ZBar QR代碼閱讀器

我正努力將ZBarSDK閱讀QR碼整合到我正在構建的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。謝謝大家。

回答

2

我解決了這個問題。有一個不正確的代表名稱。它應該是「ZbarReaderViewDelegate」。我錯過了「觀點」部分。衛生署!

​​