我正在进行此iOS练习并尝试获取存储在NSString detectionString中的条形码数据并输出到tableview。我已经声明了@property NSString * detectionString,但在我的tableview方法中它没有出现
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{
CGRect highlightViewRect = CGRectZero;
AVMetadataMachineReadableCodeObject *barCodeObject;
NSString *detectionString = nil;
NSArray *barCodeTypes = @[AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code,
AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code,
AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode];
for (AVMetadataObject *metadata in metadataObjects) {
for (NSString *type in barCodeTypes) {
if ([metadata.type isEqualToString:type])
{
barCodeObject = (AVMetadataMachineReadableCodeObject *)[_scanPreviewLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata];
highlightViewRect = barCodeObject.bounds;
**// the string that contains the barcode data -->** self.detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
break;
}
}
// Conditional statement to test if barcode was scanning
if (detectionString != nil)
{
_ScanLabel.text = detectionString;
break;
}
else
_ScanLabel.text = @"nil";
}
_ScanLaserCaptureView.frame = highlightViewRect;
}
- (NSString *)detectionString
{ **//stored string value, I want to appear on my tableview method**
return _detectionString;
}
答案 0 :(得分:0)
获取检测字符串后重新加载表格,并通过cellForRowAtIndexPath传递检测字符串。