以下是来自 Zbar SDK 的代码,它允许您扫描条形码。读取条码后,条码编号会出现在界面上的 textView 框中。您看到的 resultText.text = symbol.data 是条形码解码信息并允许条形码出现在 textView 框中的位置。所以基本上因为无论条形码解码都放在 resultText.text 中,我添加了“if”条件:
if ([symbol.data = 04176400]) {
resultText.text = @"This is a sprite bottle";
}
雪碧瓶上的条形码是 04176400。所以我希望显示文本“这是一个雪碧瓶”而不是瓶子上的条形码 04176400。但是,上面的这个“如果”条件不起作用。Xcode 显示错误“assignment to readonly property”。我相信我的“如果”条件是完全错误的,尽管它看起来很合乎逻辑。我应该用什么来代替这个,我很无能。下面是整体处理条形码数据的代码。
- (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 barcode data
resultText.text = symbol.data;
//THIS IS THE FAULTY CODE.
if ([symbol.data = 04176400]) {
resultText.text = @"This is a sprite bottle";
}
// setup our custom overlay view for the came
// ensure that our custom view's frame fits within the parent frame
// EXAMPLE: do something useful with the barcode image
resultImage.image = [info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
//Delete below in entirety for continuous scanning.
[reader dismissModalViewControllerAnimated: YES];
}