当前代码说明:iPhone应用程序包含ZBar SDK以扫描条形码。返回第一个条形码,我将symbol.data(条形码信息)发送到updateTotal。在updateTotal中,我检查扫描的条形码是否是我要查找的条形码(声明为matchBarcode。)在这种情况下,如果条形码实际上是我要查找的条形码,它会显示一条警告条形码扫描了这么说。如果没有,它会显示一条警告,说明它不是正确的条形码。
问题:无论扫描什么条形码,它都会返回不等于matchBarcode字符串。
我的想法:我认为这与条形码(symbol.data)不是NSString有关,但在ZBar SDK中它表明它是。我已经研究了一段时间,但无法解决这个问题。我确定这是一个愚蠢的错误。请帮忙。
当前代码:
- (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;
[self updateTotal:symbol.data];
NSLog(@"%@", symbol.data);
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}
-(void)updateTotal:(NSString *)barcode
{
// Barcode I am looking for
NSString *matchBarcode = @"FoundBarcode";
// Barcode Comparison
if (barcode == matchBarcode) {
// Alert stating this IS the barcode you are looking for
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct Barcode" message:barcode delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
} else {
// Alert stating this is not the barcode you are looking for
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Barcode" message:barcode delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
}
答案 0 :(得分:0)
使用NSString的isEqualToString方法。
if( [barcode isEqualToString: matchBarcode]){}